Re: Convert from int to char
- From: "Jeff" <jeffrey.summers@xxxxxxxxx>
- Date: 25 Sep 2006 18:55:39 -0700
Mocha_Java wrote:
Okay, so i have a dilemma. I have a int variable called rank that
stores integers (obviously). however, i need to display these values as
chars in another method. casting dosent help because it just converts
the integer into the unicode character which isn't the same as the
number.
heres a snippet of the problem:
char r; // as you can see, its gets pretty
repetitive and boring
if (rank == 2)
r = '2';
if (rank == 3)
r = '3';
if (rank == 4)
r = '4';
....
return r;
is there a trick to make my int number the equivalent char number?
I'm going to guess that you really mean that you want to convert it to
a character string, to display in a textbox or the like.
The trick is to use String.format
To convert your integer to a string, use
String r = String.format("%d", rank);
hth
/js
.
- References:
- Convert from int to char
- From: Mocha_Java
- Convert from int to char
- Prev by Date: Re: Convert from int to char
- Next by Date: Re: Retrieving information from MySQL Database
- Previous by thread: Re: Convert from int to char
- Next by thread: Re: Convert from int to char
- Index(es):
Relevant Pages
|