And we’ll go again. I’ll answer because I don’t have an answer for PHP yet, and someone will answer before the question is closed as duplicate.
You can’t use like double
or equivalent when numerical accuracy is required. This type of data is made to process fast and not to be exact.
The ideal in these cases is to use integers and present as you wish, with the number of houses you want. In other words, treat everything as the smallest unit possible, for example, pennies, so you don’t have to take care of the decimals. You still have to know how to handle the necessary rounding.
I doubt that’s the case, but if you don’t need calculations and all you have to do is compare, just treat it like string. This rarely applies, but is an option.
Or create or use a class for a decimal or monetary type. You have libraries ready but I don’t like them, not even the pattern.
There are several questions on the subject here:
See also What is the correct way to use the float, double and decimal types?.
Reading everything, following the link you can learn well why this happens and how to avoid in any situation in any language or software.
The problem is, using the wrong kind of data will always get you into trouble. Any attempt to circumvent with some gambit will only create the illusion of solution.
Can you put the code and check the size of the strings as well? in this example with a space between the decimal separator he just considered the numerical value and discarded the rest.
– rray
I cannot reproduce the problem. See: http://ideone.com/GQ2SkS
– bfavaretto
I’m sorry but I was wrong. In the comparison I used a variable with very similar name and so the error occurred. Sorry for my lack of attention. (It could only be that msm rsrs).
– Rafael L Ramon
Take a look at [tour]. You can accept an answer if it solved your problem. You can vote on every post on the site as well. Did any help you more? You need something to be improved?
– Maniero