alin19 Posted January 8, 2009 Share Posted January 8, 2009 i must compare a lot of numbers like this: 4734.1400 and 4734.14 the problem is that the first one is in string format and the second one into double and they are not equal, how can i change the type? Quote Link to comment https://forums.phpfreaks.com/topic/139973-solved-string-to-double/ Share on other sites More sharing options...
premiso Posted January 8, 2009 Share Posted January 8, 2009 Since you did not respond with the solution you found, here is the solution for anyone else with the same problem: You would use the (double) cast IE: <?php $firstDouble = (double)"4734.1400"; $secondDouble = 4734.14; if ($firstDouble == $secondDouble) { echo 'Yep'; }else { echo 'Nope'; } ?> I am not sure if the .1400 will cause it to not be correct, but if so, you can use number_format to just make it 2 decimal places. Quote Link to comment https://forums.phpfreaks.com/topic/139973-solved-string-to-double/#findComment-732440 Share on other sites More sharing options...
GingerRobot Posted January 8, 2009 Share Posted January 8, 2009 As long as you use the equality operator(==) and not the identical operator(===) you don't need to worry about types. Two variables are considered equal (but not identical) regardless of their type. Quote Link to comment https://forums.phpfreaks.com/topic/139973-solved-string-to-double/#findComment-732444 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.