Go doesn’t have a primitive decimal
type for arbitrary-precision fixed-point decimal numbers. Yes, you read it right. Therefore, if you need to deal with fixed-point precision there are two main options:
- Use an external package like decimal, which introduces the
decimal
type. However, the current version (1.3.1), can “only” represent numbers with a maximum of 2^31 digits after the decimal point. - Use
int64
to store and deal with these numbers. For e.g. given you need 6 precision digits, therefore79.23
,23.00
, and54.123456
, become respectively79230000
,23000000
, and54123456
.
There is an open proposal to add decimal float types (IEEE 754-2008) in the std lib. However, for now, it’s just a proposal being discussed, without guarantee it will be ever added.