Chris,

printf "credit %s,  amount %12.12d\n", $credit, $amount;

What really went wrong was to use a %d specifier. It says to truncate
a floating number into integer. Like it happens in

$ perl -e 'print int 1000*shift' 64.63
64629

If you use %f, it may improve

$ perl -e 'printf "%f",  1000*shift' 64.63
64630.000000

But I am not sure you would like %12.12f

$ perl -e 'printf "%12.12f",  1000*shift' 64.63
64629.999999999993

Maybe %12.2f

$ perl -e 'printf "%12.2f",  1000*shift' 64.63
   64630.00

Regards,
Adriano Ferreira

On 8/28/06, Howard, Chris <[EMAIL PROTECTED]> wrote:
I don't know if this is the right mailing list for this question.
Let me know if I should go somewhere else.

The issue is a number rounding problem.

Here is my perl snippet:


$credit = "64.63";
$amount = $credit * 1000;

printf "credit %s,  amount %12.12d\n", $credit, $amount;

$amount = $amount / 10;

printf "credit %s,  amount %12.12d\n", $credit, $amount;



What starts out as 64.63  ends up being 00000006462

That's bad.  Any ideas on how to fix, work around etc?

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to