Page 1 of 1

Simple ? (Solved)

Posted: Sun Mar 21, 2004 3:02 am
by malpass
Without makin quite a messy bit of substr lastindexof etc... peice of code, is there a way to get a number to have x amount of trailing 0's. Because for a price i'm getting £1.4 and I want £1.40. I know theres functions in other languages to do this, is there in Php?

Posted: Sun Mar 21, 2004 3:51 am
by starsol
Try:

Code: Select all

$price = sprintf("%01.2f", $price);

Posted: Sun Mar 21, 2004 3:55 am
by malpass
that worked fine tnx :P

Posted: Sun Mar 21, 2004 11:22 am
by doeboy
A better option my be number_format() and if 4.3 or greater you can now use money_format().