I have a regex \d+(?:[.,]\d+ that matches decimal strings with either dot or comma, like 123.123 or 123,123 so the value is valid.
Now my problem is to generate a Float value from the String which is either 123.123 or 123,123
You can use the below code.
String val = "123.123 ";
float f = Float.parseFloat(val);
String val = "123,123 "; // if other char(like comma) come, you can also write a regex to replace those set of char
val = val.replace(",",".");// assuming comma is used for decimals
float f = Float.parseFloat(val);
Float#parseFloat(). Don't know if it'll work for the comma, though...Floatorfloatif you can avoid it, try usingdouble