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

Division returns invalid results #77

Closed
frozentech opened this issue Oct 29, 2019 · 1 comment
Closed

Division returns invalid results #77

frozentech opened this issue Oct 29, 2019 · 1 comment

Comments

@frozentech
Copy link

frozentech commented Oct 29, 2019

	var environment = map[string]interface{}{
		"percent": 10,
		"amount":  1,
	}
       program, err := expr.Compile("amount * (percent / 100)", expr.Env(environment))

	output, err := expr.Run(program, environment)
	if err != nil {
		panic(err)
	}

	fmt.Println("Result : ", output)

Exprected Result : 0.1
Actual Result: 0

It looks like division is always being done using an integer data type instead of a float

@antonmedv
Copy link
Member

antonmedv commented Oct 29, 2019

Everything looks correct. If you try this in Go the same result will be.

amount * (percent / 100)
^         ^         ^
int       int       int

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