Bug #3226
closedBigDecimal: incorrectly parses "1.0x" as "1.x", and similar
Description
=begin
This problem is in the version of ruby which ships with Mac OS X 10.6, it may also exist in other versions.
BigDecimal does not parse decimals correctly when the fractional portion begins with a zero.
irb(main):001:0> BigDecimal.new("1.01")
=> #BigDecimal:1011775d0,'0.11E1',8(8)
irb(main):002:0> BigDecimal.new("1.01").to_f
=> 1.1
^----- WHAT? THAT'S NOT RIGHT!
irb(main):003:0> BigDecimal.new("1.001")
=> #BigDecimal:101166b18,'0.11E1',8(8)
irb(main):004:0> BigDecimal.new("1.001").to_f
=> 1.1
^----- WHAT? THAT'S NOT RIGHT!
irb(main):005:0> BigDecimal.new("1.0001")
=> #BigDecimal:101155ca0,'0.11E1',8(12)
irb(main):006:0> BigDecimal.new("1.0001").to_f
=> 1.1
^----- WHAT? THAT'S NOT RIGHT!
irb(main):007:0> BigDecimal.new("123.0456")
=> #BigDecimal:10113b008,'0.123456E3',8(12)
irb(main):008:0> BigDecimal.new("123.0456").to_f
=> 123.456
^----- WHAT? THAT'S NOT RIGHT!
irb(main):009:0> BigDecimal.new("123.00456")
=> #BigDecimal:10110b128,'0.123456E3',12(12)
irb(main):010:0> BigDecimal.new("123.00456").to_f
=> 123.456
^----- WHAT? THAT'S NOT RIGHT!
irb(main):011:0> BigDecimal.new("123.000456")
=> #BigDecimal:10062a470,'0.123456E3',12(16)
irb(main):012:0> BigDecimal.new("123.000456").to_f
=> 123.456
^----- WHAT? THAT'S NOT RIGHT!
This problem turned up when doing arithmetic on numbers stored as MySQL DECIMAL columns using ActiveRecord, as ActiveRecord parses those columns into BigDecimals.
=end
Updated by sakuro (Sakuro OZAWA) over 14 years ago
=begin
Fixed in p174.
See #1910.
=end
Updated by marcandre (Marc-Andre Lafortune) over 14 years ago
- Status changed from Open to Closed
=begin
=end