# compare strings

String a ="53.235"
String b ="95"

how to compare them and get b is greater than a. 95>53.235
there is Interger.getInt("53.235"), but 53.235 is not int.

###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
Float.getFloat("95").compareTo(Float.getFloat("53.235"))
Commented:
Sorry

Float.valueOf("95").compareTo(Float.valueOf("53.235"))
Commented:
Double.parseDouble(a).compareTo(Double.parseDouble(b));
Commented:
Returns:
the value 0 if anotherFloat is numerically equal to this Float; a value less than 0 if this Float is numerically less than anotherFloat; and a value greater than 0 if this Float is numerically greater than anotherFloat.

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
use Float.parseFloat or Double.parseDouble

Commented:
you can use
float aa = Float.parseFloat(a);
float bb = Float.parseFloat(b);
and after that compare the float values.
Commented:
>> hoomanv
Double.parseDouble returns a double and not a Double object.
valueOf should be used here.

or

Float.compare(Float.parseFloat(a), Float.parseFloat(b));
Double.compare(Double.parseDouble(a), Double.parseDouble(b));
Commented:
mrigank
you are rigth ;-)
Commented:
If we have
float aa = Float.parseFloat(a);
float bb = Float.parseFloat(b);

the comparison could be done simply by <, > and =
Commented:
:-) no worries.
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.