I have created a form that outputs the SUM() of a row, however, the number is a large string and I want to separate the number into values using correct numerical format such as 1,000,000.00, etc.

I found the,

number_format(); 

function, I'm just not sure how to add it too my statements,

<?php echo round($row_benTotal['SUM(ben)'],2); ?>

Any suggestions?
Thank you.

    <?php echo number_format(round($row_benTotal['SUM(ben)'],2)); ?>

      dagon;10902225 wrote:

      <?php echo number_format(round($row_benTotal['SUM(ben)'],2)); ?>

      Yet again, that worked perfectly!

      Can that also be used to change a format of $12,000 to read $12,000.00? Add decimal places when there are none?

        I understand that the function is structured as

        number_format(number,decimals,decimalpoint,separator)
        

        something like

        number_format("1000000",2);
        

        would output 1,000,000.00

        So in this syntax can I specify a "number" or does the $row_benTotal['SUM(ben)'] syntax replace that variable? Or do I not understand that at all?

          $number = 12000; 
          
          $english_format_number = number_format($number, 2, '.', ',');
          
          echo $english_format_number;
          

          result:
          12,000.00

            in your case:

            <?php echo number_format(round($row_benTotal['SUM(ben)'],2), 2, '.', ',');  ?>
            

            enough hand holding, the manual knows all

              Write a Reply...