Forum Moderators: coopster

Message Too Old, No Replies

Bankers rounding

sort of

         

ineedmoney

5:54 pm on Sep 14, 2006 (gmt 0)

10+ Year Member



Hello, I am having a little trouble. I have a php form that does some math, then displays a number that is rounded to two digits (x.xx) using this code.

<?php
printf ("%5.2f", $numbertoberounded);
?>

That part works fine, where I am running into trouble is when I try to store the rounded number in a new variable. Trying to figure it out on my own I tried

<?php
$newvariable = ("%5.2f", $numbertoberounded);
?>

which obviously didn't work. Anyone have any ideas? Thanks

barns101

5:56 pm on Sep 14, 2006 (gmt 0)

10+ Year Member



Use number_format() [php.net]

ineedmoney

6:04 pm on Sep 14, 2006 (gmt 0)

10+ Year Member



Thank you, that was exactly what i needed

working code:

<?php
$newvariable = number_format($numbertoberounded, 2, '.', '');
?>

Thanks again barns101, in the last few months you have pretty much answered every question I've come up with!

barns101

8:44 pm on Sep 14, 2006 (gmt 0)

10+ Year Member



Always happy to help :)

rokec

5:11 pm on Sep 19, 2006 (gmt 0)

10+ Year Member



And this before wasn't worked because this new variable was string, not integer as we wish.

And no, moneyformat() isn't that you need, you need MONEY!