String Format Integer With Commas, No Decimal Places and Nothing for 0 Values

ぐ巨炮叔叔 提交于 2020-01-01 05:12:47

问题


Okay before I get right into my question does anyone know if there is a tool for building string formats? What I'm thinking is something like a pretty simple user interface where you choose whether you want to display commas, zero values, dollar signs etc and then it spits out the stringformat for you. If there is one I'd love to know about it. If there's not it's the sort of thing people like me would love!

My question is. What is the string format for displaying an integer with comma separators for thousands, no decimal places and nothing for zero values.

I know the string format for an integer with comma separators and no decimal places is:

StringFormat='0,0.'

And I know the string format for displaying nothing for zero values is:

StringFormat='{}{0:#}'

But combining the two has me stumped. Thanks very much!


回答1:


I'm not 100% sure what you're after, but after comparing your two string formats, I think I know what you're after... please let me know if I am mistaken.

Once again, you almost had what I think you want... how about trying this:

StringFormat='{}{0:#,#.}'

Or just

StringFormat='#,#.'  (Just replace the '0' from your example with '#')

These are equivalent. Please note that again, these will both round the number to the nearest integer.

UPDATE >>>

Here are two very useful links to help you with your string.Formats in the future:

Custom Numeric Format Strings

Custom Date and Time Format Strings



来源:https://stackoverflow.com/questions/18844066/string-format-integer-with-commas-no-decimal-places-and-nothing-for-0-values

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