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

Method RoundCeil

decimal.go:1555–1570  ·  view source on GitHub ↗

RoundCeil rounds the decimal towards +infinity. Example: NewFromFloat(545).RoundCeil(-2).String() // output: "600" NewFromFloat(500).RoundCeil(-2).String() // output: "500" NewFromFloat(1.1001).RoundCeil(2).String() // output: "1.11" NewFromFloat(-1.454).RoundCeil(1).String() // output: "-

(places int32)

Source from the content-addressed store, hash-verified

1553// NewFromFloat(1.1001).RoundCeil(2).String() // output: "1.11"
1554// NewFromFloat(-1.454).RoundCeil(1).String() // output: "-1.4"
1555func (d Decimal) RoundCeil(places int32) Decimal {
1556 if d.exp >= -places {
1557 return d
1558 }
1559
1560 rescaled := d.rescale(-places)
1561 if d.Equal(rescaled) {
1562 return d
1563 }
1564
1565 if d.value.Sign() > 0 {
1566 rescaled.value.Add(rescaled.value, oneInt)
1567 }
1568
1569 return rescaled
1570}
1571
1572// RoundFloor rounds the decimal towards -infinity.
1573//

Callers 1

Calls 4

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

Tested by 1