RPrinceton
Programmer
Hi Everyone,
I am using the sprintf function to format a number. 1150.00/17.8 is 64.6067415730337 I want the number to be formatted as 64.60, no rounding. The code below rounds.
How do I get the sprintf function not to round? I have toyed with the idea of letting the sprintf function round to a third decimal place and then use a substr function to trim off the third decimal place. This seems somewhat kludgy. Is there a way to get sprintf not to round?
Please advise. Thx in advance.
Regards,
RPrinceton
$mv1 = 1150.00;
$mv2 = 17.8;
$mvAns = $mv1 / $mv2;
$mvFmt = sprintf("%.2f", $mvAns);
prints 64.61
I am using the sprintf function to format a number. 1150.00/17.8 is 64.6067415730337 I want the number to be formatted as 64.60, no rounding. The code below rounds.
How do I get the sprintf function not to round? I have toyed with the idea of letting the sprintf function round to a third decimal place and then use a substr function to trim off the third decimal place. This seems somewhat kludgy. Is there a way to get sprintf not to round?
Please advise. Thx in advance.
Regards,
RPrinceton
$mv1 = 1150.00;
$mv2 = 17.8;
$mvAns = $mv1 / $mv2;
$mvFmt = sprintf("%.2f", $mvAns);
prints 64.61