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

return avg function value as bigdecimal for improving accuracy #294

Merged
merged 1 commit into from
Apr 22, 2023

Conversation

a5-stable
Copy link
Contributor

Greetings 🙇‍♀️
I am having trouble getting an accurate result when using the AVG function with decimal values。
For example, when I run AVG(2, 3),

  • I expect the result to be 2.5,
  • but the actual result is 2.

I have made modifications to the code to ensure that it always returns a BigDecimal value.

before

c = Dentaku::Calculator.new
c.evaluate!("AVG(2, 3)")
#=> 2

c.evaluate!("AVG(2, 3.1)")
#=> 0.255e1

after

c = Dentaku::Calculator.new
c.evaluate!("AVG(2, 3)")
#=> 0.25e1

c.evaluate!("AVG(2, 3.1)")
#=> 0.255e1

@rubysolo rubysolo merged commit 5b399eb into rubysolo:main Apr 22, 2023
@rubysolo
Copy link
Owner

Good catch, thank you!

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 this pull request may close these issues.

None yet

2 participants