You can use number_format():
return number_format((float)$number, 2, '.', '');
Example:
$foo = "105";
echo number_format((float)$foo, 2, '.', ''); // Outputs -> 105.00
This function returns a string.
More Related Contents:
- Why is PHP printing my number in scientific notation, when I specified it as .000021?
- PHP How do I round down to two decimal places? [duplicate]
- Round to max thousand, hundred etc in PHP
- php , I want to build array from 12 values each value has max number of 2048
- Convert a date format in PHP [duplicate]
- Formatting a number with leading zeros in PHP [duplicate]
- Why does PHP consider 0 to be equal to a string?
- How to mathematically evaluate a string like “2-1” to produce “1”?
- How to pad single-digit numbers with a leading 0
- Is there an easy way to convert a number to a word in PHP?
- Print numeric values to two decimal places
- Converting words to numbers in PHP
- How to round up a number to nearest 10?
- PHP convert date format dd/mm/yyyy => yyyy-mm-dd [duplicate]
- Remove useless zero digits from decimals in PHP
- PHPMailer AddAddress()
- What is the best way to validate a credit card in PHP?
- Why does PHP echo’d text lose its formatting?
- Strange behaviour with numbers that have a leading zero [duplicate]
- PHP: Express Number in Words [duplicate]
- Rounding to nearest fraction (half, quarter, etc.)
- How to ceil, floor and round bcmath numbers?
- PHP number format
- PHP prepend leading zero before single digit number, on-the-fly [duplicate]
- Set precision for a float number in PHP
- How to display Currency in Indian Numbering Format in PHP?
- PHP float calculation error when subtracting
- How to prefix a positive number with plus sign in PHP
- PHP remove commas from numeric strings
- Format output of $SimpleXML->asXML(); [duplicate]