开发者

show decimal or double with zeros

开发者 https://www.devze.com 2022-12-13 16:00 出处:网络
i get price values from D开发者_开发问答B. now whenever the price is perhaps 5, I want to show 5.00

i get price values from D开发者_开发问答B.

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


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.


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.


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


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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消