PHP number formatting for decimal and thousand places

<?Php
$number=2512589.66785;
echo "Number = $number ";
echo "<br>With formating = ".number_format($number); //  2,512,590

// Three decimal place 
echo "<br>With formating = ".number_format($number,3); // 2,512,589.668 

// Three decimal place, '.' as decimal separator and # as thousand separator 
echo "<br>With formating = ".number_format($number,3,'.','#'); //2#512#589.668 

// Two decimal place, ',' as decimal separator and : as thousand separator 
echo "<br>With formating = ".number_format($number,2,',',':'); //2:512:589,67

// Two decimal place, '.' as decimal separator and , as thousand separator 
echo "<br>With formating = ".number_format($number,2,'.',','); //2,512,589.67
?>
One way is to round off the number or we can format the number with specifying whether to display the digits with decimal or without decimal or number of digits to display after the decimal. We can place comma ( ,) after a group of thousands. We can use other symbols in place of comma (,) for thousands and we also can replace (.) dot with symbol of our choice to be used as decimal.
Here are some examples for number formatting.

Example: Currency Formatting for Different Locales

$amount = 1234567.89;
echo number_format($amount, 2, '.', ',') . ' USD';  // Output: 1,234,567.89 USD

Example: Formatting Negative Numbers

$number = -123456.789;
echo number_format($number, 2, '.', ',');  // Output: -123,456.79

Math Functions Rounding off value pow() to get exponential value
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com











PHP video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer