views:

94

answers:

4

hi

i get price values from DB.

now whenever the price is perhaps 5, I want to show 5.00

if its 4.3 it should be 4.30.

how to convert that?

thanks

+3  A: 

You can use the string format for decimal to apply this formatting.

YourDecimal.ToString("#,##0.00");

this should show 5.00, and 4.30.

Also it will show 1,234.56 groupings.

astander
Thank you, I will try.
snarebold
+1  A: 

What data types do you use to store the price? It's a bad idea to store prices using floating point numbers because of precision issues. A fixed point number like a decimal is a better idea.

Once you're settled on a data type, you can use string formatting to display it correctly. See MSDN.

Rik
the prices are integers in Database but i do some math stuff with it and calculate a price. thx for your help.
snarebold
A: 

I never wrote a single line in Asp.net but simple search in google gave me this :

http://www.4guysfromrolla.com/aspfaqs/ShowFAQ.asp?FAQID=181 http://msdn.microsoft.com/en-us/library/dwhawy9k%28VS.71%29.aspx

jojo
I also found things by google. I like sof because of the experience people reached sometimes you see that your idea is not the best..
snarebold
+1  A: 

yourDecimal.ToString("N2") will also do the same

ram