Answer
In Float.valueOf("۱")
there is no check for different languages or character, it only checks the digits 0-9
. Integer.valueOf
uses Character.digit() to get the value of each digit in the string.
Research/Explanation
I debugged the statement Float.valueOf("۱")
with Intellij debugger. If you dive into FloatingDecimal.java, it appears this code determines which character should be counted as a digit:
digitLoop:
while (i < len) {
c = in.charAt(i);
if (c >= '1' && c <= '9') {
digits[nDigits++] = c;
nTrailZero = 0;
} else if (c == '0') {
digits[nDigits++] = c;
nTrailZero++;
} else if (c == '.') {
if (decSeen) {
// already saw one ., this is the 2nd.
throw new NumberFormatException("multiple points");
}
decPt = i;
if (signSeen) {
decPt -= 1;
}
decSeen = true;
} else {
break digitLoop;
}
i++;
}
As you can see, there is no check for different languages, it only checks the digits 0-9
.
While stepping through Integer.valueOf
execution,
public static int parseInt(String s, int radix)
executes with s = "۱"
and radix = 10
.
The parseInt method then calls Character.digit('۱',10)
to get the digit value of 1
.
See Character.digit()