106

According to Apache Commons Lang's documentation for StringUtils.isNumeric(), 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 do those characters represent?

19
  • 61
    Perhaps they represent digits in some language. Not all languages use the symbols 0 to 9 to represent digits.
    – Eran
    Oct 20, 2016 at 8:00
  • 169
    these are 1, 2 and 3 in hindi
    – Blip
    Oct 20, 2016 at 8:01
  • 11
    You can get the integer value by Integer.parseInt("१२३").
    – user4910279
    Oct 20, 2016 at 8:27
  • 9
    @dan04 Those are not numbers, those are letters that are popular to represent particular constants. Note the difference between ⅯⅭ and MC.
    – gerrit
    Oct 21, 2016 at 1:17
  • 3

5 Answers 5

200

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:

7
  • 11
    @Joker_vD well, you've not specified which overload, so yes, sure: Integer.parseInt("222", 2). Oct 20, 2016 at 10:47
  • 4
    @Joker_vD It's not even hard; there are many unsupported languages. Even if so, there's the Chinise 亿, which represents 10^8 -> this to the power of 3 would cause an overflow. List of numeral systems Oct 20, 2016 at 13:48
  • 13
    @CedricReichenbach: The key distinction there is that while 亿 is numeric (by the standards of having one of the non-None values of Numeric_Type, in this case Numeric_Type=Numeric), it's not any sort of digit. (Even if it were, you wouldn't take it to the power of 3; you would raise the radix to various powers, not the digits.) parseInt requires digits, and perhaps confusingly, the isNumeric method in this question tests for decimal digit characters (General_Category=Decimal_Number) instead of any broader category of numeric characters. Oct 20, 2016 at 19:48
  • 11
    The complete set of Devangari digits is ०१२३४५६७८९.
    – dan04
    Oct 20, 2016 at 23:28
  • 2
    @v7d8dpo4 (s)he asked if there was a way to get Integer.parseInt() to throw an exception for a 3-character numeric input string. Oct 21, 2016 at 8:57
59

The symbol १२३ is the same as 123 for the Nepali language or any other language using the Devanagari script such as Hindi, Gujarati, and so on, and is therefore is a number for Apache Commons.

3
  • 3
    That thing almost looks like "123" in Arabic numerals. Oct 21, 2016 at 18:50
  • 42
    Arabs got their numerals from Indians.
    – user2797321
    Oct 21, 2016 at 20:31
  • 5
    @rahul Arabic numbers are 1-9, not ١-٩ as commonly thought.
    – Maroun
    Oct 22, 2016 at 6:50
26

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:

1
  • 1
    It's more significant that they're of type DECIMAL_DIGIT_NUMBER than that they're in the DEVANAGARI block. There are non-digit letters in that block too. Oct 20, 2016 at 8:10
23

If you ever want to know what properties a particular "character" has (and there are quite a few), go directly to the source: Unicode.org. They have research tools that can show you most anything you would care to know.

KEEP IN MIND: The Unicode Consortium produces a specification, not software. This means that it is up to each software vendor to implement the specification as accurately as they can. So just like HTML, JavaScript, CSS, SQL, etc, there is variation between different platforms, languages, and so on. For example, I found a bug in Microsoft's .NET Framework whereby circled Latin letters A-Z and a-z -- Code Points 0x24B6 through 0x24E9 -- do not properly register as being char.IsLetter = true (bug report here). And that leads to unexpected behavior in related functionality, such as when calling the TextInfo.ToTitleCase() method (bug report here).

3
  • 1
    Great references! (Though they do make me wonder if Unicode has gone over the top!)
    – PJTraill
    Oct 20, 2016 at 21:19
  • 1
    If you want to have this sort of reference available locally, you could install uniprops.
    – TRiG
    Oct 21, 2016 at 14:44
  • 2
    @TRiG Thanks for mentioning that. Interesting utility. It does cover some of the functionality shown in the first 3 links (the original set), but I just updated my answer to include some additional links that show more advanced queries that can be done on Unicode.org that I don't see possible via uniprops. Also, it appears that uniprops is one version behind as Unicode released version 9.0 this past June. Oct 21, 2016 at 15:27
19

Symbols '१२३' are actually derived from Hindi language(Basically from Sanskrit language i.e Devanagiri) which represent numeric values just like:

१ represent 1

२ represent 2

and like wise

2
  • 4
    CORRECTION: Symbols '१२३' are actually derived from Sanskrit language (i.e., Devanagiri script as other posters have noted) Oct 20, 2016 at 16:37
  • I was surprised to learn how recently Devanāgarī took its present form – many centuries after Sanskrit was codified! So I'm skeptical of the claim that the digits belong more to Sanskrit than to Indian culture in general. Oct 22, 2016 at 3:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.