java.lang.Character getNumericValue(int codePoint)

Description

The Character.getNumericValue(int codePoint) java method 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’), lowercase (‘u0061’ through ‘u007A’), and full width variant (‘uFF21’ through ‘uFF3A’ and ‘uFF41’ through ‘uFF5A’) forms have numeric values from 10 through 35. This is independent of the Unicode specification, which does not assign numeric values to these char values.

If the character does not have a numeric value, then -1 is returned. If the character has a numeric value that cannot be represented as a nonnegative integer (for example, a fractional value), then -2 is returned.

The getNumericValue(int codePoint) method of Character class is static thus it should be accessed statically which means the we would be calling this method in this format:

Non static method is usually called by just declaring method_name(argument) however in this case since the method is static, it should be called by appending the class name as suffix. We will be encountering a compilation problem if we call the java getNumericValue() method non statically.

Method Syntax

public static int getNumericValue(int codePoint)

Method Argument

Data Type Parameter Description
int codePoint the character (Unicode code point) to be converted.

Method Returns

The getNumericValue(int codePoint) method of Character class returns an int which denotes the numeric value of the character, as a nonnegative int value; -2 if the character has a numeric value that is not a nonnegative integer; -1 if the character has no numeric value.

Compatibility

Requires Java 1.5 and up

Java Character getNumericValue(int codePoint) Example

Below is a simple java example on the usage of getNumericValue(int codePoint) method of Character class.

Sample Output

Below is the sample output when you run the above example.

java Character getNumericValue(int codePoint) example output