Simple ? (Solved)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
malpass
Forum Newbie
Posts: 3
Joined: Fri Mar 19, 2004 7:20 am

Simple ? (Solved)

Post 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?
Last edited by malpass on Sun Mar 21, 2004 3:55 am, edited 1 time in total.
starsol
Forum Newbie
Posts: 24
Joined: Thu Jul 31, 2003 8:30 am
Location: Norfolk, England.
Contact:

Post by starsol »

Try:

Code: Select all

$price = sprintf("%01.2f", $price);
malpass
Forum Newbie
Posts: 3
Joined: Fri Mar 19, 2004 7:20 am

Post by malpass »

that worked fine tnx :P
doeboy
Forum Newbie
Posts: 10
Joined: Sun Mar 21, 2004 10:18 am

Post by doeboy »

A better option my be number_format() and if 4.3 or greater you can now use money_format().
Post Reply