Format double - thousands separator with decimal but no trailing zeros

馋奶兔 提交于 2019-12-05 00:45:39

问题


I am looking for a format to use with string.Format that would print the following

double d = 123456.123456D;
double d2 = 123456D;

like

123,456.123456
123,456

{0:N6} results in

123,456.123456
123,456.000000

{0:0.######} results in

123456.123456
123456

{0:#.0} results in

123,456
123,456

I cannot workout a format that will get me to what I need. Will I need to define my own format provider ?


回答1:


You're close. Use this format:

{0:#,0.######}


来源:https://stackoverflow.com/questions/20146370/format-double-thousands-separator-with-decimal-but-no-trailing-zeros

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