troubleshooting Question

comparing float values vs string values

Avatar of ams7503
ams7503 asked on
Java
5 Comments1 Solution320 ViewsLast Modified:
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
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros