Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting a char to an integer? 2

Status
Not open for further replies.

tommyboyau

Programmer
Feb 7, 2005
47
0
0
AU
Hi Guys,
Is it possible to convert a char to an integer?
This is my situation:
char curChar;
curChar = currentLine.charAt(charCount);

Now i would like to convert curChar to an integer.
Thanks for your help.
 
Perhaps you want to know why '4' is converted to integer value 52: 52 is the value of ASCII value x34 for the character '4', and the base ASCII is contained in the code used in Java for characters. Contained - not equal!

If you want to get the value 4, you should use method parse() of class java.text.NumberFormat
 
And I thought I was familiarized with ASCII ...

Anyway, the classical way:

Code:
curChar = '4';
int i = Character.getNumericValue(curChar);

// i=4

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top