SiaFoundation / core

Core packages for the Sia project
MIT License
51 stars 7 forks source link

types: Make (Currency).String exact #146

Closed lukechampine closed 4 months ago

lukechampine commented 4 months ago
Old: "~2.529 mS"
New: "2.529378333356156158367 mS"

We discussed removing the SI units as well, and using SC exclusively (i.e. the example above would be 2.529378333356156158367 mS), but there was less consensus on that.

Since String is now exact, ExactString has been removed; if you want raw Hastings values, you can use Big or fmt.Sprintf("%d", c). If you want a rounded value, you can use standard approaches to round the float64 returned by Siacoins.

n8maninger commented 4 months ago

I'm okay with the change to String(), but I'm against the removal of ExactString().

Personally, I'd rather have String() return the value in hastings. All code works with hastings and a Currency represents a number of hastings, not Siacoin.

lukechampine commented 4 months ago

fair enough, restored.

I've also tweaked UnmarshalText to accept strings with units. This not only benefits weirdos like me who write JSON transactions by hand, but also anyone using Currency values in a human-readable config format (e.g. a YAML file specifying host prices? idk)