What PHP function can be used to format numbers with thousands separators and decimal points?
To format numbers with thousands separators and decimal points in PHP, you can use the number_format() function. This function takes a number as its first argument and optional parameters for the number of decimal places, the character used as the decimal point, and the character used as the thousands separator. By using number_format(), you can easily format numbers in a human-readable way.
$number = 1234567.89;
$formatted_number = number_format($number, 2, '.', ',');
echo $formatted_number; // Output: 1,234,567.89
Related Questions
- Are there any potential pitfalls or limitations when performing date calculations in PHP and MySQL?
- In what scenarios would a PHP developer need to compile PHP themselves and what implications does this have on accessing certain functions or extensions like BCMath support?
- Are there any recommended tutorials or resources for beginners to learn the basics of PHP and database querying?