daemonchild has asked for the wisdom of the Perl Monks concerning the following question:
hello all
--steve
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 ...
much thanks,if ($price !~ /\./) { $price .= ".00"; } else { $price =~ s/(\d*?\.\d\d).*/$1/; }
--steve
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: significant digits in computations
by btrott (Parson) on Jun 12, 2000 at 11:28 UTC | |
Re: significant digits in computations
by plaid (Chaplain) on Jun 12, 2000 at 11:30 UTC | |
by Anonymous Monk on Jun 13, 2000 at 02:58 UTC | |
Re: significant digits in computations
by Perlmage (Acolyte) on Jun 12, 2000 at 22:35 UTC | |
by hepcat72 (Sexton) on Mar 04, 2014 at 16:33 UTC | |
by lhoward (Vicar) on Jun 12, 2000 at 23:17 UTC | |
Re: significant digits in computations
by lhoward (Vicar) on Jun 12, 2000 at 16:19 UTC | |
by chromatic (Archbishop) on Jun 12, 2000 at 19:23 UTC | |
by lhoward (Vicar) on Jun 12, 2000 at 19:29 UTC |
Back to
Seekers of Perl Wisdom