John Davidson

php - number_format in between strings


I am new to php and I have this code that will supposedly display floating numbers with comma.
I have the following part of my code.

<?php echo "          
<td>Detailed Computation</td>
<td>41- Up</td>
<td>Commodity Charge: {$cc_fortyone_above} x {$diff_fortyone_above} cu. m.</td>

My Answer:
$number = 123456.789;
$formatted_number = number_format($number, 2, '.', ',');
echo "The formatted number is: $formatted_number";

This code will output:

The formatted number is: 123,456.79

The `number_format` function in PHP is used to format numbers with specified decimal points, decimal separator, and thousands separator. In this example, the number `123456.789` is formatted with 2 decimal points, a decimal separator of `.` and a thousands separator of `,`.

Rate this post

3 of 5 based on 7709 votes


© 2024 - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us