我有一个非常紧凑的方式去除十进制值中的尾随零,但我更喜欢一种不涉及字符串往返的方式,就像我现在所做的那样。这是我目前的解决方案:标准化一个System.Decimal - 条尾随零
var value = 0.010m;
value = decimal.Parse(value.ToString("G29"));
Console.WriteLine(value); // prints 0.01 (not 0.010)
所以它的工作,但你有更好的办法吗?
此外,第二个问题是decimalValue.ToString()100%符合xs:decimal?
- 当然,我可以重复截断和比较小数点,直到值不再相等。至少(0.010米== 0.01米) –
相关问题:http://stackoverflow.com/questions/3683718/is-there-a-way-to-get-the-significant-figures-of-a-decimal –
最好的办法是用Jon的答案来解答同样的问题:http://stackoverflow.com/questions/4298719/parse-decimal-and-filter-extra-0-on-the-right/4298787#4298787 – Gabe