3 ms·
This is also one more important feature/pain author didn't capture. Python is designed with scientific calc in mind. Floats are represented as pure floats like
by SriniK 15y ago
This is also one more important feature/pain author didn't capture. Python is designed with scientific calc in mind. Floats are represented as pure floats like C or C++ way.
python
>>> 2 * 3.1
6.2000000000000002
perl -e "print 2 * 3.1"
6.2
ruby -e "print 2 * 3.1"
6.2
- dexen 15y agoThat's a good point, but it may be a superficial difference, actually. The final output is not necessarily direct representation of value of variable, but may be rounded up by default for easier use. Rounded up in a configurable way. For example, in MATLAB, Octave and JavaScript, a value is displayed (formatted) as an `integer' if it's very close to an integer (closer than certain epsilon -- and that's configurable in case of M & O). At all the time, what the variable holds -- and what undergoes computations -- is a purely float value, never an integer.
- duke_sam 15y ago>>> from decimal import Decimal >>> 2 * Decimal("3.1") Decimal('6.2')