I have a text (String) an I need to get only digits from it, i mean if i have the text:
“I’m 53.2 km away”, i want to get the “53.2” (not 532 or 53 or 2)
I tried the solution in Extract digits from a string in Java. it returns me “532”.
Anyone have an idea for it?
Thanx
You can directly use a Scanner which has a
nextDouble()andhasNextDouble()methods as below:Output: 53.2