要格式化我的数字值(如果数字为零),则应显示破折号('-')而不是零。格式或MaskInput是什么?

例如。:

========================================
MyNumberFormatted      MyNumberNoFormat
========================================
       -                     0
       5                     5
       -                     0
       1                     1
========================================

最佳答案

Conditional formatting

string conditionalFormat = "{0:##;-##;-}"; // {0:positive;negative;zero}
Console.WriteLine(string.Format(conditionalFormat, 1));
Console.WriteLine(string.Format(conditionalFormat, -1));
Console.WriteLine(string.Format(conditionalFormat, 0));


https://dotnetfiddle.net/BgFc8j

关于c# - MaskInput数字格式显示破折号(-)而不是零,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54984810/

10-11 15:21