calling DivRound on a negative number returns a positive number
Author: fawkesleyCreated Sep 25, 2024Updated Jul 31, 2025
Thanks for this library - happy user for years.
Discovered something today unexpected:
a := decimal.NewFromFloat(-35.0)
fmt.Println(a.DivRound(decimal.NewFromFloat(5.0))
7This is different from Go's default behaviour:
fmt.Println(-35.0 / 5)
-7.0Am I missing something? This seems fundamentally incorrect behaviour.
Is there a way divide and preserve sign?
Cheers Paul
Source: shopspring/decimal