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.


please help, thanks
keepworkingAsked:
Who is Participating?
 
mrigankCommented:
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.

From javadocs
0
 
mrigankCommented:
Float.getFloat("95").compareTo(Float.getFloat("53.235"))
0
 
mrigankCommented:
Sorry

Float.valueOf("95").compareTo(Float.valueOf("53.235"))
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
hoomanvCommented:
Double.parseDouble(a).compareTo(Double.parseDouble(b));
0
 
Vinod_VijayanVinCommented:
use Float.parseFloat or Double.parseDouble

 
0
 
WelkinMazeCommented:
you can use
float aa = Float.parseFloat(a);
float bb = Float.parseFloat(b);
and after that compare the float values.
0
 
mrigankCommented:
>> 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));
0
 
hoomanvCommented:
mrigank
you are rigth ;-)
0
 
WelkinMazeCommented:
If we have
float aa = Float.parseFloat(a);
float bb = Float.parseFloat(b);

the comparison could be done simply by <, > and =
0
 
mrigankCommented:
:-) no worries.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.