Avatar of ams7503
ams7503

asked on 

comparing float values vs string values

I have 2 string values s1=40.239700 and s2=40.2397003.When I compare them as strings,they are not equal ie s1.equals(s2).
When I convert them to float they are found to be equal,their values when i use Float.parseFloat(s1) == Float.parseFloat(s2)
are 40.2397.

Also strings,-76.920200 and -76.9201965 are not equal but when I convert them to float,they become -76.9202 and are found
to be equal.
What is the best way to compare them
Java

Avatar of undefined
Last Comment
Mayank S

8/22/2022 - Mon