Issue
I am trying to convert string to float but I couldnt succeed.
here is my code
float f1 = Float.parseFloat("1,9698");
the error it gives is
Invalid float "1,9698";
why is it doing this? it is a valid float
Solution
I suggest you use something like this:
String text = ...;
text = text.replace(",", ".");
if(text.length() > 0) {
try {
float f = Float.parseFloat(text);
Log.i(TAG, "Found float " + String.format(Locale.getDefault(), "%f", f));
} catch (Exception e) {
Log.i(TAG, "Exception " + e.toString());
}
}
Answered By - bko
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.