Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is it new math???

Status
Not open for further replies.

admoore

IS-IT--Management
May 17, 2002
224
US
I have code that looks like this:
Code:
    $trade_avail = $trade_total - $trade_total_redeemed ;
    $trade_avail = number_format($trade_avail,2);

with $trade_total's value of 1000 and $trade_total_redeemed's value of 100, I get a result of -99

That's 1000 - 100 = -99?!

I have been through the code numerous times and can't figgure out what the heck is going on.

TIA,

-A
 
If $trade_total contained a string that began with a numeric 1 and was followed by letters, when PHP converted it to an integer to use in the formula, it would convert the "1xxx" to the number 1. That would explain your result.


Are you sure that the value of $trade_total is 1000 and not "1OOO" (the string comprised of the digit one followed by three letters "O")?





Want the best answers? Ask the best questions! TANSTAAFL!
 
are the values of $trade_total & $trade_total_redeemed 1000 and 100 respectivly or 1000.0 and/or 100.0? in other words are you doing integer math of floating point math?

Kevin Petursson
--
"Everyone says quotable things everyday, but their not famous... so nobody cares."... Some Person
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top