Jump to content

Not recognizing commas in numbers?


ERuiz

Recommended Posts

I have the following problem:

[code]
$sqlfield13 = "SELECT field13 FROM vb3_userfield WHERE userid = '".$IDPilot."' ";
$Resultfield13  = $MyDb->f_ExecuteSql($sqlfield13);
$PrevHours = $MyDb->f_GetRecord($Resultfield13);
$PrevHours = $PrevHours['field13'];
$PrevHours = number_format($PrevHours);

if ($PrevHours >= 100) {

$PrevHours = 50;

}
else {

$PrevHours = 0;

}
[/code]

In the case above, I get the following results:

if field13 = 234.3 then $PrevHours = 50
if field13 = 72.3 then $PrevHours = 0
if field13 = 1,023.3 then $PrevHours = 0

How come the last situation is giving the wrong result?

Regards,

ERuiz
Link to comment
Share on other sites

number_format is only for when you need to print them out or turn them into strings. If you want to keep doing math with a number (or do comparisons in which it is a number), no commas allowed. Don't use number_format up there.
Link to comment
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.