简体   繁体   中英

Decimal.Parse doesn't remove trailing zeros

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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