Created
September 19, 2012 12:12
-
-
Save fearoffish/3749328 to your computer and use it in GitHub Desktop.
Ruby Units: reliable??
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> Unit('1 g') >> 'ounce' | |
=> 160000045359237 oz | |
>> Unit('1 ounce') >> 'g' | |
=> 453592371600000 g | |
>> Unit('1 mm').convert_to 'cm' | |
=> 110 cm | |
>> Unit('10 ounce') >> 'g' | |
=> 45359237160000 g | |
>> Unit('100 ounce') >> 'g' | |
=> 4535923716000 g | |
>> Unit('100000 ounce') >> 'g' | |
=> 4535923716 g |
Interesting, it's Rational numbers. (Thanks to Mon_Ouie on #ruby)
>> Rational(3,4)
=> 34
>> Rational(3,4).inspect
=> "(3/4)"
>> (Unit('100000 ounce') >> 'g').inspect
=> "45359237/16 g"
>> (Unit('1 ounce') >> 'g').inspect
=> "45359237/1600000 g"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I get slightly different results:
.9.3p194 :002 > require 'ruby-units'
=> true
1.9.3p194 :003 > Unit('1 g') >> 'ounce'
=> 1600000/45359237 oz
1.9.3p194 :004 > Unit('1 ounce') >> 'g'
=> 45359237/1600000 g
1.9.3p194 :005 > Unit('1 mm').convert_to 'cm'
=> 1/10 cm