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

Comments

Projects
None yet
2 participants
@vipulnsward
Copy link
Contributor

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

@vipulnsward

This comment has been minimized.

Copy link
Contributor Author

commented Apr 16, 2014

Thanks for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.