Re: Convert from int to char




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

.



Relevant Pages

  • Convert from int to char
    ... I have a int variable called rank that ... stores integers. ... i need to display these values as ... chars in another method. ...
    (comp.lang.java.help)
  • Re: Unicode & Pythonwin / win32 / console?
    ... > * Webbrowsers for example have to display defective HTML as good as ... unknown unicode chars as "?" ... > occasionally chinese chars are displayed cryptically on non-chinese ... If the decision for default 'strict' encoding on ...
    (comp.lang.python)
  • Re: i18n/font problem in mozilla/firefox/seamonkey
    ... or any of the mozilla-suite browsers that I have (mozilla, firefox, ... the problem character codes show as ... all the chars but the accents display correctly. ...
    (comp.sys.mac.apps)
  • Re: Ranking Records in a Select Query
    ... When you actually display the ... records getting the position in the recordset / rank is easy. ... > 1) Displaying a ranking next to each entry (this is a top sellers ... >>> I'm running Access 2002. ...
    (microsoft.public.access.queries)
  • Re: HK - Honor
    ... it does still count in a few places - e.g. the highest ranked player ... will be auto-assigned battleground-leader when they join.) ... and can choose to have this rank displayed in front of your name. ... you can choose to display it. ...
    (alt.games.warcraft)