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:

  • 'u0030' through 'u0039', ISO-LATIN-1 digits ('0' through '9')
  • 'u0660' through 'u0669', Arabic-Indic digits
  • 'u06F0' through 'u06F9', Extended Arabic-Indic digits
  • 'u0966' through 'u096F', Devanagari digits
  • 'uFF10' through 'uFF19', Fullwidth 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:

  • More details on the '१' character
  • StringUtils#isNumeric implementation
  • 链接地址: http://www.djcxy.com/p/86978.html

    上一篇: 使用正则表达式来验证数字范围

    下一篇: 为什么'123'是数字?