字符串格式整数,逗号,无小数位置,0值不为空 [英] String Format Integer With Commas, No Decimal Places and Nothing for 0 Values

查看:97
本文介绍了字符串格式整数,逗号,无小数位置,0值不为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,在我明白我的问题之前,有没有人知道是否有一个工具来建立字符串格式?我在想什么就像一个非常简单的用户界面,您可以选择是否要显示逗号,零值,美元符号等,然后它会吐出stringformat。如果有一个我很想知道的话。如果没有这样的人喜欢我会喜欢的事情。



我的问题是。什么是字符串格式显示一个整数与逗号分隔符数千,没有小数位和零值没有。



我知道一个整数与逗号分隔符的字符串格式并且没有小数位数:

  StringFormat ='0,0。'
/ pre>

我知道没有显示零值的字符串格式是:

  StringFormat ='{} {0:#}'

但是,我陷入困境非常感谢!

解决方案

我不是100%肯定你以后,但比较两个字符串格式后,我认为我知道你是什么...请让我知道,如果我错了。



再一次,你几乎有我想要的/ / em你想要...如何尝试这样:

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

或只是

  StringFormat ='#,#。'(只需用'#'替换你的例子中的'0')

这些是等效的。请注意,这些将再次将数字舍入到最接近的整数。



更新>>>



以下是两个非常有用的链接,以帮助您在将来使用 string.Format



自定义数字格式字符串



自定义日期和时间格式字符串


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!

解决方案

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

这篇关于字符串格式整数,逗号,无小数位置,0值不为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆