Re: Is It Possible to Tell PHP To Output x Decimal Places Per Float?

From: Date: Tue, 10 Jun 2003 06:16:33 +0000
Subject: Re: Is It Possible to Tell PHP To Output x Decimal Places Per Float?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-150850@lists.php.net to get a copy of this message
At 2003-06-09 18:22 -0400, Dan Anderson wrote: >Is it possible to tell PHP when converting a number to a string (i.e. in >an echo or print command) to use x decimal places? > >Specifically, if I > ><?php > echo '$' . $some_price; >?> > >And some_price is $1.50, it outputs: > >$1.5 This should work: printf("$%.2f",1.50); and print: $1.50 See: http://www.php.net/manual/en/function.printf.php http://www.php.net/manual/en/function.sprintf.php Greetings, Jaap

« previous php.general (#150850) next »