MCPcopy
hub / github.com/shopspring/decimal / RoundUp

Method RoundUp

decimal.go:1605–1622  ·  view source on GitHub ↗

RoundUp rounds the decimal away from zero. Example: NewFromFloat(545).RoundUp(-2).String() // output: "600" NewFromFloat(500).RoundUp(-2).String() // output: "500" NewFromFloat(1.1001).RoundUp(2).String() // output: "1.11" NewFromFloat(-1.454).RoundUp(1).String() // output: "-1.5"

(places int32)

Source from the content-addressed store, hash-verified

1603// NewFromFloat(1.1001).RoundUp(2).String() // output: "1.11"
1604// NewFromFloat(-1.454).RoundUp(1).String() // output: "-1.5"
1605func (d Decimal) RoundUp(places int32) Decimal {
1606 if d.exp >= -places {
1607 return d
1608 }
1609
1610 rescaled := d.rescale(-places)
1611 if d.Equal(rescaled) {
1612 return d
1613 }
1614
1615 if d.value.Sign() > 0 {
1616 rescaled.value.Add(rescaled.value, oneInt)
1617 } else if d.value.Sign() < 0 {
1618 rescaled.value.Sub(rescaled.value, oneInt)
1619 }
1620
1621 return rescaled
1622}
1623
1624// RoundDown rounds the decimal towards zero.
1625//

Callers 2

roundShortestFunction · 0.45

Calls 5

rescaleMethod · 0.95
EqualMethod · 0.95
SignMethod · 0.80
AddMethod · 0.80
SubMethod · 0.80

Tested by 1