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

RoundCeil(0.002, -1) != 0.1 #140

Open
milan-enclave opened this issue Oct 11, 2024 · 0 comments
Open

RoundCeil(0.002, -1) != 0.1 #140

milan-enclave opened this issue Oct 11, 2024 · 0 comments

Comments

@milan-enclave
Copy link

When doing RoundCeiling operation to 0.002 with precision set to -1, we get 0 instead of 0.1.
However for RoundCeiling(1.002, -1) we get 1.1.

func TestDecimal_RoundCeil_Bug(t *testing.T) {
	var num apd.Decimal
	_, _, err := num.SetString("0.002")
	if err != nil {
		t.Fatal(err)
	}
	ctx := apd.Context{
		Precision:   100,
		Rounding:    apd.RoundCeiling,
		MaxExponent: 1000,
		MinExponent: -1000,
		Traps:       apd.DefaultTraps,
	}
	_, err = ctx.Quantize(&num, &num, -1)
	if err != nil {
		t.Fatal(err)
	}
	if num.String() != "0.1" {
		t.Errorf("Expected 0.1, got %s", num.String())
	}
}
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

1 participant