http://www.perlmonks.org?node_id=17681

daemonchild has asked for the wisdom of the Perl Monks concerning the following question:

hello all

i have written a script that does some price calculations based on input thru drop down menus (CGI). It all works, but I am running into problems maintaining the correct number of significant digits in calculations.

for example, trailing zeros are just obliterated, eg

2*120.00 = 240

and decimal calculations often end up with 4 or 5 trailing decimals. is there an easy way to specify 2 trailing decimal places? or am i relegated to the following ugly hacks ...

if ($price !~ /\./) { $price .= ".00"; } else { $price =~ s/(\d*?\.\d\d).*/$1/; }
much thanks,

--steve