Format Decimal 2 Places - no trailing zeroes

早过忘川 提交于 2019-12-05 21:26:59

#,#.###

Ad as many #s as needed.
To always show decimal places, use 0s instead.

You can truncate decimal places with

(int)d

If you need two decimals you can write

(int)(100*d)/100.0

(int)(100*1.99999)/100.0 ==> 1.99

If you are trying to display it as a string, try this...

yourVariable.ToString("{0:F2}");

This will format the string into a fixed point with two floating numbers.

The Microsoft Custom Numeric Format Strings and Microsoft Standard Numeric Format Strings pages have useful data you could refer to. :-)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!