Forum Moderators: coopster & phranque

Message Too Old, No Replies

Question about this code

Question about this code

         

lindajames

9:54 am on Apr 16, 2003 (gmt 0)

10+ Year Member



I have the following code in my script, and it displays minus figures in brackets. I wanted to change it to show minus figures with a "-" sign instead, the code seems very complicated to understand, can anyone help?

any suggestions would be much appreciated.

cheers
linda

sub dollar {
my $val = $_[0];
my $cursym = $curncy;
if ($usemulticur) {
$cursym = undef;
my $accid;
if ($_[1] eq undef) {
$accid = $accntcache{id};
} else {
$accid = $_[1];
}
if ($accid ne undef) {
my %acc = getaccnt($accid);
if ($acc{id} eq $accid && $acc{multicur::cursel()} ne undef) {
$cursym = multicur::sym($acc{multicur::cursel()});
}
}
$cursym = multicur::sym(multicur::basecur()) if $cursym eq undef;
}
if ($val < 0) { $val = -$val; $val = sprintf("%.2f", $val); $val = "($cursym". "$val)"; }
else { $val = sprintf("$cursym%.2f", $val);}
return $val;
}

eaden

10:05 am on Apr 16, 2003 (gmt 0)

10+ Year Member



replace this

if ($val < 0) { $val = -$val; $val = sprintf("%.2f", $val); $val = "($cursym". "$val)"; }

with this

if ($val < 0) { $val = -$val; $val = sprintf("%.2f", $val); $val = "-$cursym". "$val"; }

andreasfriedrich

10:45 am on Apr 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or you could replace

if ($val < 0) { $val = -$val; $val = sprintf("%.2f", $val); $val = "($cursym". "$val)"; }
else { $val = sprintf("$cursym%.2f", $val);}
return $val;

with


if ($val < 0) $sign = '-', $val = -$val;
return [perldoc.com] sprintf [perldoc.com]("%s %s %.2f", $sign, $cursym, $val);

Andreas