Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; my $dollar="100"; #test 1 #my $dollar="100.000"; #test 2 #my $dollar="10.000"; #test 3 my $amount= f_currency($dollar); print "Testing=$amount\n"; sub f_currency { my $num = shift @_; my $number; #make sure that the amount entering this sub has the decimal point fol +lowed by two numbers, if not dont go there. if($num=~/\d+\.\d{2}$/g) # This regular is not checking properly { $number = sprintf "%.2f", $num; # Add one comma each time through the do-nothing loop 1 while $number =~ s/^(-?\d+)(\d\d\d)/$1,$2/; # Put the dollar sign in the right place $number =~ s/^(-?)/$1\$/; return $number; }else{ #if the number dotn have the expected format just add the $ sig +n in front of it. $num="\$".$num; return $num; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Currency Format Issue
by JavaFan (Canon) on Aug 26, 2010 at 14:10 UTC | |
by Anonymous Monk on Aug 26, 2010 at 15:04 UTC | |
by Anonymous Monk on Aug 26, 2010 at 17:07 UTC | |
|
Re: Currency Format Issue
by toolic (Bishop) on Aug 26, 2010 at 14:21 UTC | |
by derby (Abbot) on Aug 26, 2010 at 14:24 UTC | |
|
Re: Currency Format Issue
by Marshall (Canon) on Aug 26, 2010 at 20:59 UTC |