Project

General

Profile

Bug #3226

BigDecimal: incorrectly parses "1.0x" as "1.x", and similar

Added by RubyBugs (A Nonymous) about 9 years ago. Updated about 8 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
ruby -v:
ruby 1.8.7 (2009-06-08 patchlevel 173) [universal-darwin10.0]
[ruby-core:29895]

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")
=> #
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")
=> #
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")
=> #
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")
=> #
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")
=> #
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")
=> #
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

History

#1

Updated by sakuro (Sakuro OZAWA) about 9 years ago

=begin
Fixed in p174.
See #1910.

=end

#2

Updated by marcandre (Marc-Andre Lafortune) about 9 years ago

  • Status changed from Open to Closed

=begin

=end

Also available in: Atom PDF