I really appreciate everybody's opinion here, really do. I've try other languages and they all have the same behaviour:
Smalltalk:
(0.6 / 0.2) asInteger
2
Python:
python -c 'print int(0.6/0.2)'
2
Ruby:
ruby -e 'print (0.6/0.2).to_i'
2
In the end I believe Dynamic languages ( perl, ruby, python ) should handle cases like this in a more elegant and seamless way.
Dynamic languages do a pretty job hiding the internal representation of numbers for the user, in the sense that you can create program without knowing whether a variable holds an integer, double, float, fixed precision or any other representation. We leave the details of picking the right representation to the compiler/interpreter, so we (users) could expect to handle such border cases also seamlessly.
As a final though,
- do you think that everybody would easily spot why int(0.6/0.2) returns 2 instead of 3 ?
- If print 3.0 returned 2.99999999 would you tell users that interpreter is doing the right job and users should stay away of using number with decimal places?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.