我有一個非常緊湊的方式去除十進制值中的尾隨零,但我更喜歡一種不涉及字符串往返的方式,就像我現在所做的那樣。這是我目前的解決方案:標準化一個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