Double string.format

社会主义新天地 提交于 2019-11-30 21:43:40

问题


I have some double values I want to convert to a string with this pattern:

0.xx or x.xx

Currently I have try this:

double.ToString("#.#0");

What should I add in order to see zero in case my number start with zero?


回答1:


just use

myDouble.ToString("0.00")

that should do the trick




回答2:


myDouble.ToString("N2")

should also work.

Have a look at

MSDN: Custom Numeric Format Strings

MSDN: Standard Numeric Format Strings




回答3:


String.Format("{0:0.00}", 111.0);



回答4:


Put a zero in front of the decimal separator:

double.ToString("0.#0");

This will always include the digit, in contrast to # which makes it optional.




回答5:


use following :

myDouble.ToString("N2")


来源:https://stackoverflow.com/questions/9869346/double-string-format

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