PHP: number_format() function
Description
The number_format() function is used to format a number (Floating number) with grouped thousands.
Version:
(PHP 4 and above)
Syntax:
number_format(number, decimals, dec_point, thousands_sep)
Parameter:
Name | Description | Required / Optional |
Type |
---|---|---|---|
number | The input number. | Required | Float |
decimals | Refer to the number of decimal points. | Optional | Integer |
dec_point | Refers the separator of decimal points. | Optional | String |
thousands_sep | Refers the thousands separator. | Optional | String |
Note: The function accepts one, two, or four parameters (not three).
Return value:
A formatted version of the number.
Value Type: String
Pictorial Presentation
Example:
<?php
$number=100000;
echo number_format($number).'<br>';
echo number_format($number, 2).'<br>';
echo number_format($number, 3).'<br>';
echo number_format($number, 2, ',', '.');
?>
Output:
100,000 100,000.00 100,000.000 100.000,00
View the example in the browser
See also
PHP: Tips of the Day
PHP: How to define an empty object in PHP?
$x = new stdClass();
stdClass is the default PHP object. stdClass has no properties, methods or parent. It does not support magic methods, and implements no interfaces.
When you cast a scalar or array as Object, you get an instance of stdClass. You can use stdClass whenever you need a generic object instance.
Ref : https://bit.ly/2Q96Wvm
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook