본문 바로가기
코틀린/[Mapping] 매핑 작업

[Kotlin][Char] getNumericValue

by jinwo_o 2024. 9. 3.

지정된 유니코드 문자가 나타내는 int 값을 반환합니다. 예를 들어, 문자 '\u216C' (로마 숫자 50) 는 값 50 을 갖는 int 를 반환합니다.대문자( '\u0041' ~ '\u005A' ), 소문자( '\u0061' ~ '\u007A' ), 전자 변형( '\uFF21' ~ '\uFF3A' 및 '\uFF41' ~ '\uFF5A' ) 형태의 문자 AZ 는 10~35 의 숫자 값을 갖습니다.

이는 이러한 char 값에 숫자 값을 할당하지 않는 Unicode 사양과는 별개입니다.
문자에 숫자 값이 없으면 -1 이 반환됩니다. 문자에 음이 아닌 정수로 표현할 수 없는 숫자 값(예: 분수 값) 이 있으면 -2 가 반환됩니다.

public static int getNumericValue(char ch) {
    return getNumericValue((int)ch);
}


print(Character.getNumericValue('2')) // 2

 

Character (Java Platform SE 8 )

Returns the int value that the specified character (Unicode code point) represents. For example, the character '\u216C' (the Roman numeral fifty) will return an int with a value of 50. The letters A-Z in their uppercase ('\u0041' through '\u005A'), lowerca

docs.oracle.com

'코틀린 > [Mapping] 매핑 작업' 카테고리의 다른 글

[Kotlin][Char] digitToInt  (0) 2024.09.03
[Kotlin][String] toInt  (0) 2024.09.03
[Kotlin][String] trim / trimStart / trimEnd  (0) 2024.08.30