New to GO- how it handles float precision 0.4 + 0.2 is 0.6

Have you looked at: big package - math/big - Go Packages ?

The math/big package is included in the standard library, no third party, no imports needed. You have arbitrary precision for Integers or rational numbers or floating point arithmetic. This explicit choice will make you careful consider your use case and the best representation.

For example: If you are calculating irrational numbers you could never “complete” your calculation if you want to represent all the digits (since irrational numbers like sqrt(2) have an infinite amount of digits)

So depending on your use case the right implementation might be big.Float, big.Rat or big.Int or just the plain old Int or Float32/64 (e.g. when your values are serialized to other Services, which expect a float32)

1 Like