Try the following
round
(PHP 3, PHP 4 )
round -- Rounds a float
Description
double round (double val [, int precision])
Returns the rounded value of val to specified precision (number of digits after the decimal point).
$foo = round (3.4); // $foo == 3.0
$foo = round (3.5); // $foo == 4.0
$foo = round (3.6); // $foo == 4.0
$foo = round (1.95583, 2); // $foo == 1.96
Note: The precision parameter is only available in PHP 4.
Sac Town wrote:
Hello,
If I have an array which outputs a product sale price (newcost) after adding a percentage to the product's cost in the database. Which ends up creating a price of something like $452.3296. How can I format the array's output to two decimal positions.
Here is parts of the query code:
$charge = (1+ ($percent/100));
query="select...cost*$charge as newcost where....";
echo this: .$row[newcost]
I can use number_format on $charge, but that won't format it when it gets multiplied by the cost. newcost is what needs to be formated - can I do that to the echo ouput above?