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

Result of operation between BigDecimal and Rational differs. #1578

Closed
vipulnsward opened this issue Mar 24, 2014 · 1 comment
Closed

Result of operation between BigDecimal and Rational differs. #1578

vipulnsward opened this issue Mar 24, 2014 · 1 comment
Milestone

Comments

@vipulnsward
Copy link
Contributor

@vipulnsward vipulnsward commented Mar 24, 2014

require 'bigdecimal'
multiplier = Rational(1,10)
number = BigDecimal.new('1.1773748397827148')
(number / BigDecimal.new(multiplier.to_f.to_s)).round * multiplier

# Result - 

# On MRI 2.1.1-
# (6/5) (Class - Rational)

# On JRuby- jruby-1.7.11
#<BigDecimal:1c7769f7,'0.0',1(4)>

gist: https://gist.github.com/vipulnsward/9736431

The above expression comes from https://github.com/rails/rails/blob/378c8d2c996558aa4108280d5f0db8daf040d0fc/activesupport/lib/active_support/number_helper/number_to_rounded_converter.rb#L61

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

Successfully merging a pull request may close this issue.

None yet
2 participants