Forums Register Login

How to convert int into a char?

+Pie Number of slices to send: Send
Hi,
I have a problem that sounds simple, but I have been struggling how to figure it out. How to convert an integer in java into a char, but keeping the value of the integer?
eg:
int x = 3;
so i want to make a char y = '3' by converting x.
if i do, char y = (char)x; the value of y is no longer 3!! Please help.
+Pie Number of slices to send: Send
If you want the char '3' and not the byte value of 3 then do this:

[ April 06, 2004: Message edited by: Michael Morris ]
+Pie Number of slices to send: Send
Thank you for your prompt reply. I appreciate. Have a good one.
+Pie Number of slices to send: Send
Michael got you on the right track...
now how would you handle numbers greater than 9?? two-digit numbers? three-digit numbers?
+Pie Number of slices to send: Send
What about negative numbers?
+Pie Number of slices to send: Send
How about first converting int to Integer
From Integer get a String
From String -- method toCharArray() gets you a character array...
See where your hand is? Not there. It's next to this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1436 times.
Similar Threads
long to Integer conversion
converting a string to an int
char
int to hex
how the program works?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 01:37:09.