Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lvhuat opened this issue Sep 8, 2022 · 2 comments · Fixed by #301
Closed

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

lvhuat opened this issue Sep 8, 2022 · 2 comments · Fixed by #301

Comments

@lvhuat
Copy link

lvhuat commented Sep 8, 2022

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
Copy link
Author

lvhuat commented Sep 8, 2022

Please add more test cases for decimal.Decimal{}

@mwoss
Copy link
Member

mwoss commented Dec 31, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants