Tuesday, December 11, 2012

PHP Number Format

I wanted to format a price number with two decimal places, for example 1245, here's what I did.

//code sample
number_format(1245, 2, '.', ',');

//output is 1,245.00

//First parameter (1245) is our input number
//Second paramter (2) is the number of decimal places you want
//Third parameter ('.') is the character for decimal separator
//Fourth parameter (',') is the character for thousands separator

No comments:

Post a Comment

Powered by Blogger.