Thanks for the answers. I wasn't interested as much in fixed decimal solutions as understanding why what appeared to be the same floating-point math on the surface was returning different results.
I also posted this question on Stack Overflow and I think the answers there are pretty comprehensive: https://stackoverflow.com/questions/47213283/why-is-there-a-difference-between-floating-point-multiplication-with-literals-vs On Thursday, November 9, 2017 at 5:16:37 PM UTC-7, Trig wrote: > > There are 3rd-party packages/vendors that help with this, such as: > > https://github.com/shopspring/decimal > > On Thursday, November 9, 2017 at 5:36:03 PM UTC-6, Erik Swan wrote: >> >> Why are the following unequal in Go? Is this a bug, or is it by design? >> If it's by design, why does this occur and is this type of behavior >> documented anywhere? >> >> https://play.golang.org/p/itEV9zwV2a >> >> package main >> >> import ( >> "fmt" >> ) >> >> func main() { >> x := 10.1 >> >> fmt.Println("x == 10.1: ", x == 10.1) >> fmt.Println("x*3.0 == 10.1*3.0:", x*3.0 == 10.1*3.0) >> fmt.Println("x*3.0: ", x*3.0) >> fmt.Println("10.1*3.0: ", 10.1*3.0) >> } >> >> Produces: >> >> x == 10.1: true >> x*3.0 == 10.1*3.0: false >> x*3.0: 30.299999999999997 >> 10.1*3.0: 30.3 >> >> >> -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.