shopspring / decimal

Arbitrary-precision fixed-point decimal numbers in Go
Other
6.41k stars 623 forks source link

How to represent "0.00" #354

Open omkar9194 opened 9 months ago

omkar9194 commented 9 months ago

I find that if we do var zero = decimal.FromString("0.00") Then print zero/ assign it to string after conversion, Instead of printing 0.00, 0 is printed.

Similarly if we do var seventy = decimal.FromString("0.70") Then print zero/ assign it to string after conversion, Instead of printing 0.70, 0.7 is printed.

Is there a pre-existing solution for this? If not, can this be added as a feature?

mwoss commented 9 months ago

By default trailing zeroes are truncated when decimals are converted to string representation. We are discussion potential enhancement in this PR https://github.com/shopspring/decimal/pull/296

serprex commented 7 months ago

In the meantime, you can use d.StringFixed(2) if you only want printing 2 decimal places