Retrieving the first digit of a number
Posted
by Michoel
on Stack Overflow
See other posts from Stack Overflow
or by Michoel
Published on 2010-06-03T16:28:13Z
Indexed on
2010/06/03
16:34 UTC
Read the original article
Hit count: 138
java
|type-conversion
Hi, I am just learning Java and am trying to get my program to retrieve the first digit of a number - for example 543 should return 5, etc. I thought to convert to a string, but I am not sure how I can convert it back? Thanks for any help.
int number = 534;
String numberString = Integer.toString(number);
char firstLetterChar = numberString.charAt(0);
int firstDigit = ????
© Stack Overflow or respective owner