Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -1753,13 +1753,16 @@ func (d Decimal) Ceil() Decimal {

// Truncate truncates off digits from the number, without rounding.
//
// NOTE: precision is the last digit that will not be truncated (must be >= 0).
// NOTE: precision is the last digit that will not be truncated.
// Positive values truncate decimal places; negative values truncate
// integer digits (e.g., -2 rounds to nearest hundred).
//
// Example:
//
// decimal.NewFromString("123.456").Truncate(2).String() // "123.45"
// decimal.NewFromString("5432").Truncate(-2).String() // "5400"
func (d Decimal) Truncate(precision int32) Decimal {
if precision >= 0 && -precision > d.exp {
if -precision > d.exp {
return d.rescale(-precision)
}
return d
Expand Down