?
Solved

compare strings

Posted on 2006-04-12
10
Medium Priority
?
221 Views
Last Modified: 2010-03-31
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
0
Comment
Question by:keepworking
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 5

Expert Comment

by:mrigank
ID: 16439873
Float.getFloat("95").compareTo(Float.getFloat("53.235"))
0
 
LVL 5

Assisted Solution

by:mrigank
mrigank earned 1000 total points
ID: 16439885
Sorry

Float.valueOf("95").compareTo(Float.valueOf("53.235"))
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 16439886
Double.parseDouble(a).compareTo(Double.parseDouble(b));
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 5

Accepted Solution

by:
mrigank earned 1000 total points
ID: 16439903
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
 
LVL 5

Assisted Solution

by:Vinod_VijayanVin
Vinod_VijayanVin earned 200 total points
ID: 16439906
use Float.parseFloat or Double.parseDouble

 
0
 
LVL 11

Assisted Solution

by:WelkinMaze
WelkinMaze earned 200 total points
ID: 16439917
you can use
float aa = Float.parseFloat(a);
float bb = Float.parseFloat(b);
and after that compare the float values.
0
 
LVL 5

Assisted Solution

by:mrigank
mrigank earned 1000 total points
ID: 16439940
>> 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
 
LVL 14

Expert Comment

by:hoomanv
ID: 16439986
mrigank
you are rigth ;-)
0
 
LVL 11

Expert Comment

by:WelkinMaze
ID: 16439992
If we have
float aa = Float.parseFloat(a);
float bb = Float.parseFloat(b);

the comparison could be done simply by <, > and =
0
 
LVL 5

Expert Comment

by:mrigank
ID: 16439994
:-) no worries.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month15 days, 14 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question