http://qs321.pair.com?node_id=97091


in reply to Re: Re: Re: Filthy Floats
in thread Filthy Floats

Perl does lots of magic, especially in the way it handles scalars as strings, integers and floats simultaneously.

In your case, the value is being handled as a string until you force Perl to treat it as a number (by using it in a multiplication). The result is a floating point value, subject to the inaccuracies described elsewhere. If it comes up with a seemingly exact value sometimes, well, welcome to the mystery :)

I take it the issue here is that you want a leading zero, or some other normalization? If so, then use sprintf to enforce the format you want. Try <%=sprintf("%1.2f",$target)%> for instance.