Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts

    how to rid this of decimal places

    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?

    PHP Code:
    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>
    <br>
    Your bank account has matured!
    <br><br>
    Previous balance: $"
    .makecomma($fetch->bankold)."<br>
    Interest earned: $"
    .makecomma($intrestsum)."<br>
    Current balance: $"
    .makecomma($newnewmoney)."<br>
    <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:

    PHP Code:
    function makecomma($input)

    {

      

       if(
    strlen($input)<=3)

       { return 
    $input; }

       
    $length=substr($input,0,strlen($input)-3);

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

       return 
    $formatted_input;


    and the message i get in inbox is this:

    Code:
    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.
    Last edited by Dan13071992; 01-11-2012 at 05:47 PM.
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #2
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Have a look at number_format()
    PHP Code:
    $num '442819.26';

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

    $num '7823140.26';

    makecomma$num );        // 7,823,140,.26
    number_format$num); // 7,823,140.26 
    Last edited by kbluhm; 01-11-2012 at 05:13 PM.

  • #3
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    sorry i ment i dont want the decimal point or anything after it
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #4
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    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:
    PHP Code:
    $num '7823140.26';

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

  • #5
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    would it be $numberformat?
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #6
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Quote Originally Posted by Dan13071992 View Post
    would it be $numberformat?
    ?... not sure what you're asking.

    You'd replace this:
    PHP Code:
    makecomma($intrestsum
    ...with this:
    PHP Code:
    number_format($intrestsum
    There's really no need for that makecomma() function, it does essentially what number_format() does, but incorrectly and with less flexibility. :P

  • #7
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    sorry i had read what you wrote wrong, thanks for the help its all working now
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •