I have done this before and It just won't work now. I am trying to print a dollar amount, but it keeps only showing the .00 (cents). Here is my code:
# Tried this:
$_table_data .= qq~
</td>
<td align="center" valign="top" style="padding-top: 5px">
\$~ . sprintf("%.2f", "$_srp_price") . qq~
</td>
</tr>~;
# Result: .95 SHOULD be: 4.95
# And this:
$_table_data .= qq~
</td>
<td align="center" valign="top" style="padding-top: 5px">
~ . '$' . sprintf("%.2f", "$_srp_price") . qq~
</td>
</tr>~;
# Result: .95
# And This:
$_table_data .= "\$";
$_table_data .= sprintf("%.2f", "$_srp_price");
# Result: Same thing: .95
# And This:
$_table_data .= '$';
$_table_data .= "$_srp_price";
# Result: Same thing: .95
# And This:
$_table_data .= '\$';
$_table_data .= $_srp_price;
# Result: .95 Same thing again.
# And this:
$_table_data .= '\\$';
$_table_data .= $_srp_price;
# Result: \.95
# And this (works without the dollar sign
$_table_data .= sprintf("%.2f", "$_srp_price");
# Result: 4.95
I have tried all kinds of different variations. I cannot get this to work no matter what I try!
Later in the code I have
$_table_data inserted into another variable which is inside a html table.
I don't know what I did different, but this is just one page of a lot of them. Here is my main index.cgi file that calls the different 'modules' I am using:
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:standard :cgi-lib escapeHTML);
use Mail::Sendmail;
use Digest::MD5;
use Crypt::CBC;
use Crypt::Blowfish;
use LWP::UserAgent;
use Calendar::Simple;
use OGC::Sid;
use strict;
use Time::Duration;
use vars qw($cookie $sessid $sessref $page $loggedin $pgtitle $_title
+%in $_pp_browser $reqdir $pg $_page_content $_dur_time);
$_dur_time = time();
ReadParse(\%in);
Any ideas?
I would really appreciate any advice as to how I can do this. I don't know if one of the modules I'm using is messing this up. I also call HTTP::BrowserDetect later in a config file.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.