I'm interested in a way to accurately subtract 2 float's in Go.
I've tried to use the math/big
library but I can't get an accurate result.
I've used the big.js library in Javascript which solves this problem. Is there a similar library/method for Go arithmetic?
package main
import (
"fmt"
"math/big"
)
func main() {
const prec = 200
a := new(big.Float).SetPrec(prec).SetFloat64(5000.0)
b := new(big.Float).SetPrec(prec).SetFloat64(4000.30)
result := new(big.Float).Sub(a, b)
fmt.Println(result)
}
Result: 999.6999999999998181010596454143524169921875