decimal icon indicating copy to clipboard operation
decimal copied to clipboard

[Bug] (decimal.Decimal{}).NumDigits == 5

Open lvhuat opened this issue 2 years ago • 1 comments

code in decimal

func (d Decimal) NumDigits() int {
	// Note(mwoss): It can be optimized, unnecessary cast of big.Int to string
	if d.IsNegative() {
		return len(d.value.String()) - 1
	}
	return len(d.value.String())
}

when d.value is nil, d.value.String() return "<nil>" instead of "0"

func (x *Int) Text(base int) string {
	if x == nil {
		return "<nil>"
	}
	return string(x.abs.itoa(x.neg, base))
}

// String returns the decimal representation of x as generated by
// x.Text(10).
func (x *Int) String() string {
	return x.Text(10)
}

lvhuat avatar Sep 08 '22 16:09 lvhuat

Please add more test cases for decimal.Decimal{}

lvhuat avatar Sep 08 '22 16:09 lvhuat

Thanks for the report! The issue has been fixed via #301 and will be included in the next release.

mwoss avatar Dec 31 '23 12:12 mwoss