Issue
If there is:
String s="0.0234000ETH";
What is one of the most efficient/better ways to isolate the floating part so that:
float result=0.0234000; //or just 0.0234
Keep in mind I do not care loosing the String
part (ETH in this case).
Solution
Use this:
float number = Float.parseFloat(s.replaceAll("[^\\d.]", ""));
System.out.println(number);
Or, what's already mentioned in the comments: Get the substring which only contains the number. Then you can parse it to your data type.
String s = "0.0234000ETH";
String part1 = s.substring(0,8);
float value = Float.parseFloat(part1);
System.out.println(value);
Answered By - Enrico
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.