1

In my coding I get the values as float and then store it into table.

 $new_priceint=((float)$new_price*100);
 $used_priceint=((float)$used_price*100);

The variable $new_priceint and $used_priceint are stored in db. For example the value is 439. The same value just I fetched to compare the current value is modified or not, I really didn't get the correct answer.

If I subtract the $newpriceint > $newpriceintdbvalue, this gives the result of 5.6843418860808E-14. For half day I tried for this to get the value as "zero". Actually the db value is '439' and also the current value is '439' but this current is in float. IS not the same value. 439 = 439 right or float(439) == 439 is wrong i dont know really. Anybody can help to solve this issue. How to compare the float values with other values in php

Thanks in advance

Rithu
  • 1,169
  • 3
  • 16
  • 38
  • possible duplicate of [Compare floats in php](http://stackoverflow.com/questions/3148937/compare-floats-in-php) or of [Is it correct to compare two rounded floating point numbers using the == operator?](http://stackoverflow.com/questions/236439/is-it-correct-to-compare-two-rounded-floating-point-numbers-using-the-operato?rq=1) – Mark Baker Oct 11 '13 at 14:29
  • What is the type of the field in database where you store the numbers? Is is INT, FLOAT, DECIMAL, DOUBLE maybe? – Kamil Oct 11 '13 at 14:31
  • @Kamil I stored in table value type of FLOAT – Rithu Oct 11 '13 at 14:33
  • 1
    `(float)439 == (float)439` =) – el Dude Oct 11 '13 at 14:33
  • General remark: storing prices as FLOATs in a database is going to bite you back pretty hard at some point, see http://stackoverflow.com/a/66678/393701 – SirDarius Oct 11 '13 at 14:46
  • Is 439 the value before multiplication by 100, or after? – Patricia Shanahan Oct 11 '13 at 14:53
  • after multiply by hundred, the value is 400 – Rithu Oct 11 '13 at 14:55
  • Just now i checked the type of each variable. The db stored variable type is in string type and the current value i get from URL is in double – Rithu Oct 11 '13 at 14:56
  • How to compare both type of varibles but both are the same one – Rithu Oct 11 '13 at 14:56

0 Answers0