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

Method RoundFloor

decimal.go:1580–1595  ·  view source on GitHub ↗

RoundFloor rounds the decimal towards -infinity. Example: NewFromFloat(545).RoundFloor(-2).String() // output: "500" NewFromFloat(-500).RoundFloor(-2).String() // output: "-500" NewFromFloat(1.1001).RoundFloor(2).String() // output: "1.1" NewFromFloat(-1.454).RoundFloor(1).String() // outp

(places int32)

Source from the content-addressed store, hash-verified

1578// NewFromFloat(1.1001).RoundFloor(2).String() // output: "1.1"
1579// NewFromFloat(-1.454).RoundFloor(1).String() // output: "-1.5"
1580func (d Decimal) RoundFloor(places int32) Decimal {
1581 if d.exp >= -places {
1582 return d
1583 }
1584
1585 rescaled := d.rescale(-places)
1586 if d.Equal(rescaled) {
1587 return d
1588 }
1589
1590 if d.value.Sign() < 0 {
1591 rescaled.value.Sub(rescaled.value, oneInt)
1592 }
1593
1594 return rescaled
1595}
1596
1597// RoundUp rounds the decimal away from zero.
1598//

Callers 1

Calls 4

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

Tested by 1