ziarkaen Posted November 29, 2007 Share Posted November 29, 2007 hi all, im trying to add two strings taken from ebay in the format "7.88", "0.23", "3", etc. using the ordinary '+' operator the result is unpredictably wrong i do not know why this happens, but I have heard of loss of presision when using floating point numbers?! any help would be appreciated examples are: P=£0.99 | S=£6.99 | T=£.00 P=£0.99 | S=£5.99 | T=£1.00 P=£0.95 | S=£7.95 | T=£2.00 where T should be P add S thanks, Ben Quote Link to comment Share on other sites More sharing options...
Azu Posted November 29, 2007 Share Posted November 29, 2007 Okay so there are between 0 and 2 numbers after the decimal point? Try this $p=intval($p*100); $s=intval($s*100); $t=(($p*$s)/100); Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 29, 2007 Share Posted November 29, 2007 Please show us the code you are using. Ken Quote Link to comment Share on other sites More sharing options...
ziarkaen Posted November 29, 2007 Author Share Posted November 29, 2007 intval code worked!!! thanks v much i was beginning to think I should have sticked with c++ lol thanks again, ben Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.