Jump to content

number_format


dudejma

Recommended Posts

Okay, I've read the manual on number_format and I'm not sure if I'm just not grasping it or I'm missing something but I've found out that when I use number format, it only gives me one digit. Like this:

 

I have my code:

$newPay = number_format($oldPay + $distance * .40, 2);

.

 

I've echoed out $oldPay and it gives the correct number because it comes directly from a database. When I echo out $newPay, I get the same value as $oldPay. Whenever I take away number_format, it still does the same thing. Obviously, I'm pretty new to PHP coding and not very advanced but I'm just not sure what I'm missing. Any help? Thanks.

Link to comment
https://forums.phpfreaks.com/topic/254577-number_format/
Share on other sites

number_format() doesn't quite do what you're expecting. Try round instead.

 

He is correct in saying number_format doesn't quite do what youre expecting. It will only keep the decimal points if there are more than two it will limit them to two places. A solution for you would be:

 

$newPay = round($oldPay + $distance * .40, 2);

Link to comment
https://forums.phpfreaks.com/topic/254577-number_format/#findComment-1305450
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.