Welcome to Dream.In.Code
Become an Expert!

Join 150,416 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,021 people online right now. Registration is fast and FREE... Join Now!




Formatting data type

 
Reply to this topicStart new topic

Formatting data type

XenoSophist
1 Apr, 2008 - 06:56 PM
Post #1

New D.I.C Head
*

Joined: 2 Oct, 2007
Posts: 36



Thanked: 1 times
My Contributions
I have a small SQL database that uses a column for money cost. I am using Visual C# to program the user interface. My problem is that the money datatype I used shows numbers to 4 decimal places. What do I need to change so that it my DataList in C# only displays 2 decimal places?

This post has been edited by XenoSophist: 1 Apr, 2008 - 06:57 PM
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Formatting Data Type
1 Apr, 2008 - 08:14 PM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Well you could use ToString() and pass the {0:C} format to it like so


csharp

YourMoneyVariable.ToString("{0:C}");



You could also use String.Format() and pass the same format to it, something like


csharp

Console.WriteLine(String.Format("Dollar Value Is: {0:C}",YourMoneyVariable));



Hope that helps smile.gif
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Formatting Data Type
1 Apr, 2008 - 08:32 PM
Post #3

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,660



Thanked: 314 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
You should be able to convert it to a string and simply format the string. I am not quite sure this is a database specific question or if you should be asking this in ASP.NET or not... but you could try

CODE

<%# String.Format("{0:c}", container.dataitem("columnwithmoney").ToString()) %>


This may work. The trick here is that we just need to format the data as it is presented.

smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 08:06PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month