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

Method Truncate

decimal.go:1755–1761  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

1753//
1754// decimal.NewFromString("123.456").Truncate(2).String() // "123.45"
1755func (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.
1764func (d *Decimal) UnmarshalJSON(decimalBytes []byte) error {

Callers 4

TestDecimal_QuoRemFunction · 0.80
TestDecimal_QuoRem2Function · 0.80
RoundCashMethod · 0.80

Calls 2

ensureInitializedMethod · 0.95
rescaleMethod · 0.95

Tested by 3

TestDecimal_QuoRemFunction · 0.64
TestDecimal_QuoRem2Function · 0.64