Project

General

Profile

Actions

Bug #7024

closed

90 * 1.1 => 99.00000000000001

Added by Bahanix (Julien -) over 11 years ago. Updated over 11 years ago.

Status:
Rejected
Assignee:
-
Target version:
ruby -v:
ruby 1.9.3p194 (2012-04-20 revision 35410) [i686-linux]
Backport:
[ruby-core:47535]

Description

$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [i686-linux]
$ irb
1.9.3p194 :001 > 901.1
=> 99.00000000000001
1.9.3p194 :002 > 90.0
1.1
=> 99.00000000000001

Expected value: 99.0

Thanks for your job every one!

Updated by marcandre (Marc-Andre Lafortune) over 11 years ago

  • Status changed from Open to Rejected

This is expected from floating point calculations; you'll get this result in other languages too.

Checkout http://0.30000000000000004.com/

Updated by alexeymuranov (Alexey Muranov) over 11 years ago

Julien, try

(90 * Rational(11, 10)).to_f

or

(90 * '1.1'.to_r).to_f

or

(90 * 1.1.rationalize).to_f

Actions

Also available in: Atom PDF

Like0
Like0Like0