Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By eRaaaa

Thread: How to convert integer to String

  1. #1
    mCoder is offline Member
    Join Date
    Sep 2011
    Posts
    2
    Rep Power
    0

    Default How to convert integer to String

    Actually I want to calculate some numbers from my database and want to show in a textfield. I know that to show any output in the textfield, need to use this variable_name.setText(var_total);.

    Here is my code that I tried:
    Java Code:
    int c1 = rs.getInt("Credits1");
    int c2 = rs.getInt("Credits2");
    int c3 = rs.getInt("Credits3");
    int c4 = rs.getInt("Credits4");
    int c5 = rs.getInt("Credits5");
                            
    int getCredits = c1 + c2 + c3 + c4 + c5;
    txtTotalCredits.setText(getCredits);
    But this is not working. Because getCredits is an integer type.
    So please tell me, how could I resolve this problem.

    Thanks in advance.

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default Re: How to convert integer to String

    txtTotalCredits.setText(""+getCredits);
    or
    txtTotalCredits.setText(String.valueOf(getCredits) );
    or
    ...
    or..
    google has nothing to find?
    mCoder likes this.

  3. #3
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default Re: How to convert integer to String

    May I add:
    txtTotalCredits.setText(String.format("%d credits",getCredits));

Similar Threads

  1. convert integer to binary
    By leepikamukharji in forum New To Java
    Replies: 2
    Last Post: 04-30-2011, 04:19 AM
  2. convert integer to double
    By himanwish in forum New To Java
    Replies: 4
    Last Post: 03-17-2011, 01:55 AM
  3. convert unsigned integer to signed integer in java?
    By diskhub in forum New To Java
    Replies: 6
    Last Post: 05-17-2010, 12:50 AM
  4. How to convert Integer[] to int[]
    By Nithya in forum New To Java
    Replies: 26
    Last Post: 02-11-2010, 05:41 PM
  5. how to convert a string to an integer
    By LAW in forum New To Java
    Replies: 6
    Last Post: 11-09-2009, 03:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •