1

Using TextField to place double/integer numbers, want to change any number with "," to number with "." and remove multiple dots and commas.

String test = "0....,,,,,,,....754568";
test.replaceAll(<?IDK?>, ".");

<?IDK?> means that I don't know what to put there.

Examples:
4,54.5
6,,,,26.2
0....,,,,,,,....7545680.754568
7...27.2

2 Answers 2

6

If you want to replace all . or , by . :

test.replaceAll("[.,]+", ".");
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, exactly matches what I need.
0

You can have a regular expression, for example, to identify numbers which have more than one dot or comma you can use the following :

\d+[.,]{2,}+\d

You can adjust it based on your needs.

If you want to test it, this website is useful : https://www.freeformatter.com/java-regex-tester.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.