Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Multiplication problem

by mwah (Hermit)
on Dec 10, 2007 at 15:23 UTC ( [id://656140]=note: print w/replies, xml ) Need Help??


in reply to Multiplication problem

Your "formula" seems overly complicated (and probably broken). For the start, I'd go with a quick&dirty simple & minimal variant and advance from there:

#!/usr/bin/perl use strict; use warnings; my @prices = qw'.1 17.95 0 10000 0.00 21 .22'; my $qtyx = 3; print "Content-type: text/html\n\n"; print map "$_ x $qtyx, total costs are: ". VIEWPRICE( MAKEPRICE($_)*$qtyx + ) .'<br />', @prices; sub MAKEPRICE { (my $mp = sprintf "%.2f", (shift)) =~ tr/.//d; return $mp } sub VIEWPRICE { my $vp = sprintf "%03d", (shift); $vp =~ s/(..)$/.$1/ or $vp = sprintf "%.2f",$vp; return $vp }

This prints (<br /> translated):

Content-type: text/html .1 x 3, total costs are: 0.30 17.95 x 3, total costs are: 53.85 0 x 3, total costs are: 0.00 10000 x 3, total costs are: 30000.00 0.00 x 3, total costs are: 0.00 21 x 3, total costs are: 63.00 .22 x 3, total costs are: 0.66

Regards

mwa

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://656140]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2024-04-23 09:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found