[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 7280
  • Last Modified:

PHP Number Format - Decimal Places

Hi,

I have this line in my PHP code that displays a decimal number, but sometimes there is like 10 decimal places. I need to shorten it to display only 2 decimal places.

For example, now:

It will display: 69.9438095238

I need it to display like: 69.94

Here is the line of PHP code:

<?php

echo ('<td class=' . $css_class . ' align=default >'.$_SESSION["avg"].'</td>');

?>

How can I make it display with only 2 decimal places?

0
fcruz5
Asked:
fcruz5
1 Solution
 
glcumminsCommented:
echo ('<td class=' . $css_class . ' align=default >'.round($_SESSION["avg"], 2).'</td>');
0
 
ll_jaxnCommented:
string number_format ( float $number [, int $decimals [, string $dec_point, string $thousands_sep]] )


http://us3.php.net/manual/en/function.number-format.php
0
 
SumanGhoshCommented:
Its good to use the round($value, 2) function first and then wrap it with number_format($value, 2).
It should look like $number_format(round($value, 2), 2)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now