decimal
decimal copied to clipboard
Wrong value in same numbers: Div + Mul
fee := decimal.NewFromFloat(0.0295)
feeMin := decimal.NewFromFloat(4)
feeAmt := decimal.NewFromFloat(2.95)
fmt.Println((4 / 2.95) * 0.0295)
fmt.Println(feeMin.Div(feeAmt).Mul(fee).String())
fmt.Println(feeMin.Mul(fee.Div(feeAmt)).String())
0.04
0.03999999999999999975
0.04
This example: https://play.golang.org/p/qaAtlBHTJpY
Hi @vsokolovsky555. Thanks for mentioning this issue. This is a known bug (maybe someone could call it feature) with Div
meethod that can produce not exact results. This is strictly related to exponent of the producded result. I will take a look. Thanks!
@mwoss any luck on this issue?
@durango As many people mentioned this behaviour as a bug I will try to change the way of how Div
rounds the result. Hopefully, I will find time at weekend to do it, but I can't promise anything. Lately, I'm quite busy :<
Are there any updates on this? Thanks