How may I convert a numerical value in the form of a char to a double value?
I've tried just casting the char to a double but... it doesn't work like that I'm guessing as char such as '4' will convert to 52.0 in doubles.
So is there a way to convert a char with a value of say
char c = '4'
to a double value of 4.0 where I can actually perform mathematical calculations on the value?
This is just a little program I created to show that casting a numeric char directly to a double won't work the way I was expecting.
public class conversion
{
public static void main(String args[])
{
char eight = '8';
char four = '4';
double d2 = (char)eight;
double d1 = (char)four;
System.out.println(d2);
System.out.println(d1);
double result = (d2 / d1);
System.out.println(result);
}
}
outputs:
56.0
52.0
1.0769230769230769
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…