简体   繁体   English

如何格式化数字但显示所有位数的精度?

[英]How can I format a number but show all digits of precision?

When a user goes to edit a number, I want to format a number to have a thousands separator in one case (and a percentage sign in another) but I want to be able to show absolutely all available digits of precision. 当用户去编辑数字时,我想格式化数字以在一种情况下具有千位分隔符(在另一种情况下具有百​​分号),但是我希望能够显示绝对所有可用的精度数字。

When the number is being displayed, its format is simply {0:0,0;-0,0; - } 显示数字时,其格式仅为{0:0,0;-0,0; - } {0:0,0;-0,0; - } , (or {0:0,0.00;-0,0.00; - } to show two decimal places), but when my control goes into edit mode, I want to switch to displaying something very similar, but showing all available digits of precision. {0:0,0;-0,0; - } (或{0:0,0.00;-0,0.00; - }以显示两位小数),但是当我的控件进入编辑模式时,我想切换为显示非常相似的内容,但显示所有可用数字的精度。 Is there any way to do this short of creating a format string that looks like this? 除了创建像这样的格式字符串外,还有什么方法可以做到这一点?

{0:0,0.#############################;-0,0.###...

I want to do something similar with percentages. 我想对百分比做类似的事情。 I want to displayed value to be {0:0.00 %;-0.00 %; - } 我想将值显示为{0:0.00 %;-0.00 %; - } {0:0.00 %;-0.00 %; - } until the user activates the cell for editing, at which time the format should still be a percentage, but showing more digits of precision if they exist in the underlying value. {0:0.00 %;-0.00 %; - }直到用户激活单元格进行编辑为止,此时格式仍应为百分比,但是如果基础值中存在精度数字,则显示更多精度。

Thanks 谢谢

This question is similar to yours. 这个问题和你的相似。 (The answer is that it's not possible with the .NET built-in custom numeric formatting.) (答案是,.NET内置自定义数字格式不可能。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM