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 6 of 6
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Posts
    712
    Thanks
    165
    Thanked 0 Times in 0 Posts

    Problem in displaying number format with comma and two decimal places

    Good day!

    I use round syntax in displaying my computation and the result is correct. but it has no comma.
    Like for example the result is 3020, I want it to 3,020.00

    I have this syntax:

    PHP Code:
    $Amount round(($Hours/8)* $Rate2); 
    but when I tried number_format it displayed correct but I think the data or the amount is wrong because I sum amount in other earnings before i change the format, the output is 5524.28, but when I change my format of my amount the sum of other earnings and amount become 2507.88, so the data that get in amount is only 3.6.

    i only want is adding comma, with changing the real amount or data.

    Thank you so much....

  • #2
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,233
    Thanks
    51
    Thanked 100 Times in 99 Posts
    You have to use number_format() such as this.

    PHP Code:
    You have number_format($bankaccountmoney in your account.

    $Amount round(($Hours/8)* $Rate2); 
    $Amount2 number_format($Amount); 
    http://php.net/manual/en/function.number-format.php
    Been a sign maker for 7 years. My business:
    American Made Signs

  • Users who have thanked myfayt for this post:

    newphpcoder (11-14-2011)

  • #3
    Regular Coder
    Join Date
    Aug 2010
    Posts
    712
    Thanks
    165
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by myfayt View Post
    You have to use number_format() such as this.

    PHP Code:
    You have number_format($bankaccountmoney in your account.

    $Amount round(($Hours/8)* $Rate2); 
    $Amount2 number_format($Amount); 
    http://php.net/manual/en/function.number-format.php
    I treis this, but still change the output number....the equal number of 3,200 is become 463 only.

    before the total earnings is; 6056.55 and when I change the number format the basic pay from 3020, become 3,020 which is correct but when I sum to other deduction the output become 2788.13

  • #4
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,233
    Thanks
    51
    Thanked 100 Times in 99 Posts
    number_format shouldn't affect the amount in any way. The code posted was an example, you'll have to determine the best way to do it. Another idea to try is this.

    PHP Code:
    $Amount number_format(round(($Hours/8)* $Rate2)); 
    Been a sign maker for 7 years. My business:
    American Made Signs

  • Users who have thanked myfayt for this post:

    newphpcoder (11-14-2011)

  • #5
    Regular Coder
    Join Date
    Aug 2010
    Posts
    712
    Thanks
    165
    Thanked 0 Times in 0 Posts
    this is my code:
    PHP Code:
      $sql "SELECT w.EMP_ID, w.RATE, e.Hours FROM $ADODB_DB.wage w, $PAYROLL.earnings e WHERE w.EMP_ID = '$currentEmpID'";
      
    $RsEarnings $conn2->Execute($sql);

      
    $Rate      trim($RsEarnings->fields['RATE']);
      
    $Hours      trim($RsEarnings->fields['Hours']);
      
      
    $Hours substr($Hours05);
      
    $Hours str_replace(':''.'$Hours);
      

     
    $Amount number_format(round(($Hours/8)* $Rate2));


    $TotEarn number_format(round($Amount), 2);

    rate 302
    hours
    57.55
    amount 
    2,173
    totearn 
    2.00 //wrong 

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Um, number_format is a string. You are now trying to operate mathematically on a string which may produce improper results. This is especially true if you provide a , within the number, as its now directly a string which cannot be converted to a number. When it tries, it will truncate from the first invalid character, which is the comma from the thousand separator. Use number_format or money_format only on the very last result to display as a string. Alternatively, you may use [s]printf to format with the decimal points and commas, but will lose the locale knowledge of the currency in use (so you need to manually add a $ or £ for example).


  •  

    Posting Permissions

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