mirror of
https://github.com/shopspring/decimal.git
synced 2024-11-22 20:40:48 +01:00
Use QuoRem to avoid extra ops
This commit is contained in:
parent
2faaec71dd
commit
080be114dd
1 changed files with 3 additions and 4 deletions
|
@ -440,11 +440,10 @@ func (d Decimal) RoundFair(places int32) Decimal {
|
||||||
|
|
||||||
// First, truncate the number to see if there are trailing decimal places.
|
// First, truncate the number to see if there are trailing decimal places.
|
||||||
// If there are it can't end in 5.
|
// If there are it can't end in 5.
|
||||||
exp := new(big.Int).Exp(tenInt, shift, zeroInt)
|
|
||||||
rounded := new(big.Int).Quo(d.value, exp)
|
|
||||||
|
|
||||||
tmp := new(big.Int)
|
tmp := new(big.Int)
|
||||||
if tmp.Mul(rounded, exp).Cmp(d.value) != 0 {
|
exp := new(big.Int).Exp(tenInt, shift, zeroInt)
|
||||||
|
rounded, _ := new(big.Int).QuoRem(d.value, exp, tmp)
|
||||||
|
if tmp.Cmp(zeroInt) != 0 {
|
||||||
return d.Round(places)
|
return d.Round(places)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue