English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

for example

number_format(66,666.666,1); //display 66,666.67

but i want the result 66,666.66 which is in 1 decimal only and dont want it to rounded up. How can i do that?

2006-10-01 19:44:53 · 5 answers · asked by kit 1 in Computers & Internet Programming & Design

5 answers

First of all, let's look at the documentation:

http://www.php.net/number_format

The first argument must be a float (as in floating-point number), and 66,666.666 is not a valid float (floats cannot have commas in them). Further, if you want to display two decimal points, the second argument must be 2. So the correct call would be:

number_format(66666.666, 2); //display 66,666.67

2006-10-03 07:00:30 · answer #1 · answered by NC 7 · 0 2

Php Number_format

2016-10-30 05:20:07 · answer #2 · answered by Anonymous · 0 0

You could do it like this for unpadded:


$number = 66666.6666;

$number = ($d = strpos($number,'.')) ? number_format(floor($number)) . substr($number,$d,3) : number_format($number);

echo $number

?>

And like this for padded:


$number = 66666.6666;

$number = number_format(floor($number * 100) / 100, 2);

echo $number;

?>

the output includes commas and decimal i.e.

66,666.66

2006-10-02 10:04:43 · answer #3 · answered by dt01pqt_pt 2 · 0 0

Number_format

2016-12-12 11:39:17 · answer #4 · answered by Anonymous · 0 0

function fixAmount($amount) {
$amount = $amount * 100;
$amount = floor($amount);
$amount = $amount / 100;
return $amount;
}

$amount - fixAmount(66666.666);
//amount = 66666.66

2006-10-02 00:57:09 · answer #5 · answered by fwiiw 4 · 0 0

fedest.com, questions and answers