John Davidson

php - number_format in between strings

0 comments
Message:


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 "          
<table>
<tr>
<td>Bracket</td>
<td>Detailed Computation</td>
<td>Total</td>
</tr>
<tr>
<td>41- Up</td>
<td>Commodity Charge: {$cc_fortyone_above} x {$diff_fortyone_above} cu. m.</td>
<td>{$total_fortyone_above}</td>
</tr>
</table>";
?>


My Answer:
php
$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 9863 votes

Comments




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