6 ms·
I prefer Python's explicit approach to decimal types: $ python -c "from decimal import Decimal as D; print(D('.1')+D('.2')-D('.3'))" 0.0 Or if you prefer
by arocks 12y ago
I prefer Python's explicit approach to decimal types:
$ python -c "from decimal import Decimal as D; print(D('.1')+D('.2')-D('.3'))"
0.0
Or if you prefer true rational numbers:
$ python -c "from fractions import Fraction as F; print(F('.1')+F('.2')-F('.3'))"
0
$ python -c "from fractions import Fraction as F; print(F('3.1415927'))"
31415927/10000000
- herge 12y agoWhat other languages call all-important features Python calls a module in the standard library :)
- draegtun 12y agoYou could say the same thing about perl5 then :) $ perl -E "use bignum; say .1 + .2 - .3" 0 $ perl -E "use bigrat; say .1 + .2 - .3" 0 $ perl -E "use bigrat; say 3.1415927 / 1" 31415927/10000000 ref: http://perldoc.perl.org/bignum.html http://perldoc.perl.org/bignum.html | http://perldoc.perl.org/bigrat.html http://perldoc.perl.org/bigrat.html