when i check with condition 08 or 09 or 010 and above leading with 0 in org.apache.commons.lang3.math.NumberUtils.isNumber("08")

- 39
- 1
- 6
-
Hello. Could you [edit] your question and add description of problem you are facing like compilation error, exception stacktrace, expected result vs actual (incorrect?) result? For now it is similar to "I have a problem with my car, when I try to start the engine [and here problem description stops]". – Pshemo Feb 19 '20 at 13:55
4 Answers
Method isNumber is deprecated:
isNumber(String str) Deprecated. This feature will be removed in Lang 4.0, use isCreatable(String) instead
Use isCreatable for above purpose.
Your above requirement to check ocatl kind of values will be detected via isCreatable method:
org.apache.commons.lang3.math.NumberUtils.isCreatable("08") // this will return true.
this method Checks whether the String a valid Java number.
Valid numbers include hexadecimal marked with the 0x or 0X qualifier, octal numbers, scientific notation and numbers marked with a type qualifier (e.g. 123L).
Non-hexadecimal strings beginning with a leading zero are treated as octal values. Thus the string 09 will return false, since 9 is not a valid octal value. However, numbers beginning with 0. are treated as decimal.
reference official docs

- 4,271
- 4
- 38
- 62
Use isCreatable instead. I assume isNumber works basically the same way.
"Non-hexadecimal strings beginning with a leading zero are treated as octal values." Thus the string 09 will return false, since 9 is not a valid octal value. However, numbers beginning with 0. are treated as decimal."
00-07 are numbers. 08--010 are not interpreted as octal numbers, but that is a library issue.
See What do numbers starting with 0 mean in python?
When in doubt read the manual.

- 1,881
- 2
- 20
- 44
-
"Use isCreatable instead. I assume isNumber works basically the same way." yes, it just calls through – serv-inc Apr 20 '22 at 10:20
Use isParsable()
NumberUtils.isCreatable("09"); // FALSE
NumberUtils.isNumber("09"); // FALSE
NumberUtils.isParsable("09"); // TRUE

- 936
- 3
- 16
- 37