Use a custom format sub such as the following I wrote:
Hope this helps.my $num = 244.83; print "'" . str($num, 8, 3) . "'\n"; sub str { ## This sub is used to return a formatted numeric string. ## It has three arguments which are: the number sent, the ## desired width (including decimal point, if any), and ## the number of decimal places (optional) in that order. ## The number is right-justified. my ($sentnum, $width, $precision) = @ARG; ## Check to see if a non-zero precision was sent. if ($precision) { ## print to var using decimal point. $sentnum = sprintf("%" . "$width.$precision" . "f", $sentnum); } else { ## print in integer format. $sentnum = sprintf("%" . "$width.0" . "f", $sentnum); } ## change decimals to commas $sentnum =~ tr/./,/; return $sentnum; }
Update: could move tr/./,/ to above else statement.
Results: ' 244,830'
In reply to Re: Using printf with %.1f
by jlongino
in thread Using printf with %.1f
by alexsc01
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |