Check if string contains only digits
how about
how about
The number of digits of an integer n in any base is trivially obtained by dividing until you’re done:
Use setRoundingMode, set the RoundingMode explicitly to handle your issue with the half-even round, then use the format pattern for your required output. Example: gives the output: EDIT: The original answer does not address the accuracy of the double values. That is fine if you don’t care much whether it rounds up or down. But … Read more