简体   繁体   English

根据自定义格式在C#中设置十进制值的格式

[英]Formatting decimal values in C# based on custom format

I'm facing an issue in my project while formating decimal values based on custom format. 在基于自定义格式设置十进制值的格式时,我的项目遇到了问题。
The format set is 格式设置为

>>>,>>>,>>>,>>>,>>9.99 

which is taken from DB. 这是从数据库中获取的。

And in C# code we were initially replacing '>' with '#' and '9' with '0'. 在C#代码中,我们最初将'>'替换为'#',将'9'替换为'0'。
It works fine for values like 25.65 etc but for values like 5.00 it was showing 05.00. 对于25.65等值,它工作正常,但对于5.00,则显示05.00。
So what we did was replaced '>' with '#' and '9' with '#' which solved our issue. 因此,我们的工作被替换为“#”和“ 9”,从而解决了我们的问题。
But this lead to a new issue again. 但这又导致了新的问题。 It works fine for values like 25.65,5.00. 它适用于25.65,5.00之类的值。
But for values 0.00 it shows .00. 但对于值0.00,则显示.00。 Can anyone help on this? 有人可以帮忙吗?

Replace '>' with '#' 将“>”替换为“#”

  • and 9 with # before the . 和9在#之前加上#。

  • and 9 with 0 after the . 和9在0之后加上0。

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

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