Skip to content

Result of operation between BigDecimal and Rational differs. #1578

@vipulnsward

Description

@vipulnsward
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions