Quote:
Originally Posted by ownedbycats
Mostly out of curiosity about how something works again.
program: $#timesread + 1
This returns '1'
program: add($#timesread, 1)
This returns '1.0'
Why are they different?
(also just realized I should be using $$, oops...)
|
Because the add() function was defined forever ago to always return a float. This can't change without potentially breaking templates.
The add operator (+) checks the result and converts the float to an int if the fractional part is zero. One can argue that defining it this way was wrong, but so be it.
Before you ask: no, I am not going to change the behavior of either one.
Note that the results are arithmetically identical.
If you don't like the ".0" then use round(), floor(), ceil(), fractional_part(), or format_number() to convert it. Or use re() to strip off the .0, as in
Code:
re(add(3), '^(.*)\.0$', '\1')