[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] printf ?



I am trying to get the following CGI.pm script to print two decimal places
as in "$125.15" I can get two zeros tacked on the end but that's not quite
what I am after. printf does not print anything.

TIA

Bob Callaghan

#!/usr/local/bin/perl

use CGI ':standard';

$tax = 7.00;
$other = 10.00;

print header;
print start_html('A Simple Example'),
    h1('A Simple Example'),
    start_form,
    "What's your name? ",textfield('name'),
                                p,
    "Multiplication factor ",textfield('multi'),

    p,
    "How many items do you want? ",
    popup_menu(-name=>'quantity',
               -values=>['1','2','3','4','5','6','7'],

-labels=>{'1'=>'One','2'=>'Two','3'=>'Three','4'=>'Four',


'5'=>'Five','6'=>'Six','7'=>'Seven'}),


    "What Size?",
    popup_menu(-name=>'size',
               -values=>['100.00','200.00','300.00'],

-labels=>{'100.00'=>'Small','200.00'=>'Medium','300.00'=>'Large'
}),
    p,
    submit,
    end_form,
    hr;

if (param()) {
    printf
        "Hi ",em(param('name')),
        p,
        "Your price for the above order is: \$
%0.2f",em(((param('quantity')*(param('size')))+$tax+$other)*param('multi')."
.00"),
        hr;
}
print a({href=>'../cgi_docs.html'},'This is a broken link');

#you can see the two zeros tagged on the end but when I use a
multlipication factor of .5 I get "$117.1.00" #not good.

************************************************************************
***        The nice thing about going to a Drive In, If you          ***
***      didn't like the movie you can always slash the seats!       ***
************************************************************************