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

Re: [MacPerl] printf ?



bobc@navnet.net (Robert Callaghan) wrote
>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';
>

deletia

>
>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.
>

You can use sprintf to format something into a string - I suggest that you use
this, and then build up your HTML output string by concatenation. I'd suggest
that you play with sprintf from the command line to get familiar with the
syntax, though I do think that you want the format string "%0.2f", as you've
used. Of course, printf should work in the same way, however, it'll probably
be easier to develop using sprintf.

Bob

________________________________________________________________
          Bob Wilkinson, Perl Programmer, Pindar plc
Tel: +44 (0)1904 613040    Email: B.Wilkinson@pindar.co.uk
Fax: +44 (0)1904 613110    URL: http://www.connection.co.uk/bob
________________________________________________________________
  I don't speak for my employer - er, they made me say that..
________________________________________________________________