Decimal.Parse 不会删除尾随零 [英] Decimal.Parse doesn't remove trailing zeros
本文介绍了Decimal.Parse 不会删除尾随零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在标记为重复之前,请阅读问题.
我发现很多关于 SO 的问题都抱怨 Decimal.Parse
不保留尾随零.但就我而言,Decimal.Parse(String)
根本不删除尾随零.
I found many questions on SO complaining that Decimal.Parse
doesn't keep trailing zeros. But for my case Decimal.Parse(String)
doesn't remove trailing zeros at all.
Decimal.Parse("3.000").ToString() ' ==> "3.000"
Double.Parse("3.000").ToString() ' ==> "3"
我在这里遗漏了什么吗?
Am I missing something here?
推荐答案
您可以使用 数字格式
Decimal.Parse("3.100").ToString("G")
或者使用如下解决方法:
Or with some workaround like the following:
StrDec = Decimal.Parse("3.100").ToString
If strDec.Contains(".") Then strdec = strdec.TrimEnd("0")
这篇关于Decimal.Parse 不会删除尾随零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文