Truncate truncates off digits from the number, without rounding. NOTE: precision is the last digit that will not be truncated (must be >= 0). Example: decimal.NewFromString("123.456").Truncate(2).String() // "123.45"
(precision int32)
| 1753 | // |
| 1754 | // decimal.NewFromString("123.456").Truncate(2).String() // "123.45" |
| 1755 | func (d Decimal) Truncate(precision int32) Decimal { |
| 1756 | d.ensureInitialized() |
| 1757 | if precision >= 0 && -precision > d.exp { |
| 1758 | return d.rescale(-precision) |
| 1759 | } |
| 1760 | return d |
| 1761 | } |
| 1762 | |
| 1763 | // UnmarshalJSON implements the json.Unmarshaler interface. |
| 1764 | func (d *Decimal) UnmarshalJSON(decimalBytes []byte) error { |