Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.