Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By Norm

Thread: Converting

  1. #1
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default Converting

    How can I convert an int like for example convery 10000 to 10k, convert 150000 to 150k 1000000 to 1m and etc.

    How can I do this?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    You want to take a int value, say 10000 and convert it to the String "10k".
    Divide the int by 1000, convert the results to a String and concatenate a "k".
    Same logic for "1m"

  3. #3
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default

    Quote Originally Posted by Norm View Post
    You want to take a int value, say 10000 and convert it to the String "10k".
    Divide the int by 1000, convert the results to a String and concatenate a "k".
    Same logic for "1m"
    How can I check whether or not it has a decimal? For example if it is 1500 it would say 1.5k but if it's 1000 it would say 1k.

    EDIT:: nvm, figured it out! :)

    Thank you!
    Last edited by PhQ; 08-21-2011 at 06:26 PM.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    How can I check
    You could use the if statement to check the value of a variable.
    You could check to see if there are remainders after a division by 1000 by using the % operator.
    PhQ likes this.

Similar Threads

  1. Help me Converting jar to jpg and jpg to jar
    By nap_patague in forum Advanced Java
    Replies: 0
    Last Post: 03-20-2011, 09:33 AM
  2. Converting from long to int
    By peterhabe in forum New To Java
    Replies: 2
    Last Post: 02-20-2011, 07:14 PM
  3. converting hex to dec -
    By Symbiot in forum New To Java
    Replies: 3
    Last Post: 05-27-2010, 02:56 PM
  4. need help converting
    By sr20guy in forum New To Java
    Replies: 16
    Last Post: 04-02-2010, 02:07 PM
  5. Converting URL to URI
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-26-2007, 11:15 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
  •