Floor returns the nearest integer value less than or equal to d.
()
| 1710 | |
| 1711 | // Floor returns the nearest integer value less than or equal to d. |
| 1712 | func (d Decimal) Floor() Decimal { |
| 1713 | d.ensureInitialized() |
| 1714 | |
| 1715 | if d.exp >= 0 { |
| 1716 | return d |
| 1717 | } |
| 1718 | |
| 1719 | exp := big.NewInt(10) |
| 1720 | |
| 1721 | // NOTE(vadim): must negate after casting to prevent int32 overflow |
| 1722 | exp.Exp(exp, big.NewInt(-int64(d.exp)), nil) |
| 1723 | |
| 1724 | z := new(big.Int).Div(d.value, exp) |
| 1725 | return Decimal{value: z, exp: 0} |
| 1726 | } |
| 1727 | |
| 1728 | // Ceil returns the nearest integer value greater than or equal to d. |
| 1729 | func (d Decimal) Ceil() Decimal { |