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

Text('f'): 0 x 100 = 000 #136

Open
Sroose opened this issue Jun 17, 2024 · 1 comment
Open

Text('f'): 0 x 100 = 000 #136

Sroose opened this issue Jun 17, 2024 · 1 comment

Comments

@Sroose
Copy link

Sroose commented Jun 17, 2024

When multiplying 0 with some number, the resulting Text('f') shows too many zeroes. I expect the result to return "0"

x := new(apd.Decimal)
_, _ = x.SetFloat64(0)

multiplier := new(apd.Decimal)
_, _ = multiplier.SetFloat64(100)

result := new(apd.Decimal)
_, _ = apd.BaseContext.Mul(result, x, multiplier)

fmt.Println(result.Text('f')) // 000
@mike-mcgann
Copy link

The Reduce method will remove those zeros:

x := new(apd.Decimal)
_, _ = x.SetFloat64(0)

multiplier := new(apd.Decimal)
_, _ = multiplier.SetFloat64(100)

result := new(apd.Decimal)
_, _ = apd.BaseContext.Mul(result, x, multiplier)

result.Reduce(result)
fmt.Println(result.Text('f')) // 0

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

No branches or pull requests

2 participants