⊗ppPmSFNF 156 of 447 menu

Formatting a Number in PHP

number_format

Given a string:

<?php $str = '12345678'; ?>

Make it into a string:

'12 345 678'

Given a number:

<?php $number = 9876543.21; ?>

Format the number so that it has thousands separators (space) and two digits in the fractional part:

'9 876 543.21'

Given a number:

<?php $price = 1234.5678; ?>

Format the number with thousands separators (dot), two digits in the fractional part, and a currency symbol:

'€1.234,57'
byenru