V
VK
I still think that FAQ 4.6, the proposed code _and_ the native
toFixed() method as described in specs is a brut force liking of the
Holy Grail and a hot grill
One part of task is to ensure that numbers without fractional part or
with a fractional part shorter than specified will be padded by the
needed amount of zeros. This say with pattern *.dd
2 > "2.00"
1.2 > "1.20"
and similar. This is a purely textual task without any math really
involved, just like padding hours and minutes with zero if lesser than
10.
Other part is to _round_ the numbers with fractional part longer than
needed so to fit it into pattern. This say with pattern *.dd
2.234 > 2.23
1.035 > 1.04
5.56789 > 5.57
and similar. This task presumes the conventional rounding mechanics
where the rounding goes from rightmost number to left, with 0,1,2,3,4
rounded down and 5,6,7,8,9 rounded up.
btw thanks to Dr.Stockton for correction, I don't have any "anti-2
prejudice" that was a typo in my previous post.
There could be some exact IEEE-imposed limits for the second task
calculated based on the famous tables by Lasse Reichstein Nielsen:
<http://groups.google.com/group/comp.lang.javascript/msg/3833df1762d81fee>
and Thomas Lahn
<http://groups.google.com/group/comp.lang.javascript/msg/efec4b1ca3ddfbe9>
but truthfully I think that anyone in need to round say US
$10.66666666666666666666666666 needs not a programming but a medical
assistance - and urgently. So there is nothing wrong to set a proc
imposed limit for argument - say no more than 10 digits after period -
and after that either throw exception or return NaN.
P.S. IMO because toFixed() was defined so ambiguously by its actual
purpose, different producers concentrated either on the first task -
and then 1.035.toFixed(2) == '1.03' - or on the second task - and then
1.035.toFixed(2) == '1.04'
So a really useful program would do both task equally effectively but
keeping in code obvious that these are really two very weakly related
objectives. Such program IMO would be both practically useful and
educational.
toFixed() method as described in specs is a brut force liking of the
Holy Grail and a hot grill
One part of task is to ensure that numbers without fractional part or
with a fractional part shorter than specified will be padded by the
needed amount of zeros. This say with pattern *.dd
2 > "2.00"
1.2 > "1.20"
and similar. This is a purely textual task without any math really
involved, just like padding hours and minutes with zero if lesser than
10.
Other part is to _round_ the numbers with fractional part longer than
needed so to fit it into pattern. This say with pattern *.dd
2.234 > 2.23
1.035 > 1.04
5.56789 > 5.57
and similar. This task presumes the conventional rounding mechanics
where the rounding goes from rightmost number to left, with 0,1,2,3,4
rounded down and 5,6,7,8,9 rounded up.
btw thanks to Dr.Stockton for correction, I don't have any "anti-2
prejudice" that was a typo in my previous post.
There could be some exact IEEE-imposed limits for the second task
calculated based on the famous tables by Lasse Reichstein Nielsen:
<http://groups.google.com/group/comp.lang.javascript/msg/3833df1762d81fee>
and Thomas Lahn
<http://groups.google.com/group/comp.lang.javascript/msg/efec4b1ca3ddfbe9>
but truthfully I think that anyone in need to round say US
$10.66666666666666666666666666 needs not a programming but a medical
assistance - and urgently. So there is nothing wrong to set a proc
imposed limit for argument - say no more than 10 digits after period -
and after that either throw exception or return NaN.
P.S. IMO because toFixed() was defined so ambiguously by its actual
purpose, different producers concentrated either on the first task -
and then 1.035.toFixed(2) == '1.03' - or on the second task - and then
1.035.toFixed(2) == '1.04'
So a really useful program would do both task equally effectively but
keeping in code obvious that these are really two very weakly related
objectives. Such program IMO would be both practically useful and
educational.