View Full Version : Resolved how to rid this of decimal places

01-11-2012, 04:56 PM
hi guys, ive got a function where you earn intrest every 24 hours on money you put in the bank, however even with my makecomma function it still produces decimale places, which i dont want it to, could anyone help please?

if (time() <= $fetch->banktime){

$intrestsum = $fetch->bank / 100 * 6;
$newnewmoney = $fetch->bank + $intrestsum;

mysql_query("UPDATE users SET bank='$newnewmoney' WHERE username='$fetch->username'");

$sendmessage= "
<b>Federal Bank</b>
Your bank account has matured!
Previous balance: $".makecomma($fetch->bankold)."<br>
Interest earned: $".makecomma($intrestsum)."<br>
Current balance: $".makecomma($newnewmoney)."<br>
Visit the <b>Federal Bank</b> to withdraw or renew your balance.

mysql_query("INSERT INTO `inbox` (`id`, `to`, `from`, `message`, `date`, `read`) VALUES ('', '".dbSafe($fetch->username)."', '".dbSafe($fetch->username)."', '".dbSafe($sendmessage)."', '".dbSafe($date)."', '0');") or die (mysql_error());


the make comma function is:

function makecomma($input)



{ return $input; }


$formatted_input = makecomma($length).",".substr($input,-3);

return $formatted_input;


and the message i get in inbox is this:

Federal Bank
Your bank account has matured!

Previous balance: $4,000,007
Interest earned: $442,819,.26
Current balance: $7,823,140,.26

Visit the Federal Bank to withdraw or renew your balance.

can you see how the first one comes out normally, thats because its in the database, however the other two are posted from the page if the time is >=
$fetch->banktime (in the code its <= as for testing purposes, but they come out with the decimal place,, but it doesnt put the decimal place into the database, which is good but it still displays as a decimal.

any help would be great.

01-11-2012, 05:10 PM
Have a look at number_format (http://www.php.net/number_format)()

$num = '442819.26';

makecomma( $num ); // 442,819,.26
number_format( $num, 2 ); // 442,819.26

$num = '7823140.26';

makecomma( $num ); // 7,823,140,.26
number_format( $num, 2 ); // 7,823,140.26

01-11-2012, 05:27 PM
sorry i ment i dont want the decimal point or anything after it

01-11-2012, 05:36 PM
Read through that link I posted. The documentation names the second parameter as control over the number of decimals places you want to display, which defaults to zero:

$num = '7823140.26';

number_format( $num ); // 7,823,140

01-11-2012, 05:38 PM
would it be $numberformat?

01-11-2012, 05:39 PM
would it be $numberformat?

?... not sure what you're asking.

You'd replace this:

...with this:


There's really no need for that makecomma() function, it does essentially what number_format() does, but incorrectly and with less flexibility. :P

01-11-2012, 05:46 PM
sorry i had read what you wrote wrong, thanks for the help :) its all working now :)