Decimal.Parse doesn't remove trailing zeros

╄→尐↘猪︶ㄣ 提交于 2019-12-23 05:38:10

问题


Please read the question before flagging as duplicate.

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?


回答1:


You can achieve this using number formatting

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") 


来源:https://stackoverflow.com/questions/40953111/decimal-parse-doesnt-remove-trailing-zeros

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!