Why is '१२३' numeric?
According to the documentation the String '१२३' is numeric.
Since I believed this might be a mistake in the documentation, I ran tests to verify the statement. I found that according to Apache Commons it is numeric.
Why is this String numeric? What are those characters representing?
Because that "CharSequence contains only Unicode digits" (quoting your linked documentation).
All of the characters return true for Character.isDigit
:
Some Unicode character ranges that contain digits:
Many other character ranges contain digits as well.
१२३
are Devanagari digits:
१
is DEVANAGARI DIGIT ONE, u0967
२
is DEVANAGARI DIGIT TWO, u0968
३
is DEVANAGARI DIGIT THREE, u0969
符号123与尼泊尔语或使用梵文脚本的任何其他语言(如印地语,古吉拉特语等)的123相同,因此是Apache Commons的编号。
You can use Character#getType
to check the character's general category:
System.out.println(Character.DECIMAL_DIGIT_NUMBER == Character.getType('१'));
This will print true
, which is an "evidence" that '१' is a digit number.
Now let's examine the unicode value of the '१' character:
System.out.println(Integer.toHexString('१'));
// 967
This number is on the range of Devanagari digits - which is: u0966
through u096F
.
Also try:
Character.UnicodeBlock block = Character.UnicodeBlock.of('१');
System.out.println(block.toString());
// DEVANAGARI
Devanagari is:
is an abugida (alphasyllabary) alphabet of India and Nepal
"१२३" is a "123" (Basic Latin unicode).
Reading:
StringUtils#isNumeric
implementation 上一篇: 使用正则表达式来验证数字范围
下一篇: 为什么'123'是数字?