Results 1 to 5 of 5
  1. #1
    EasternDude is offline Member
    Join Date
    Oct 2014
    Posts
    5
    Rep Power
    0

    Default Double number formatting

    i have a real number. example:

    double number = 1.95842175;

    i want to split it into 2 integers:

    int a1 = 1;

    and

    it a2 = 95 (2 numbers after '.')


    HOW?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Double number formatting

    Use cast and multiplication and subtraction in the right order.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Double number formatting

    Or convert it to a String and parse it.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  4. #4
    EasternDude is offline Member
    Join Date
    Oct 2014
    Posts
    5
    Rep Power
    0

    Default Re: Double number formatting

    Quote Originally Posted by Norm View Post
    Use cast and multiplication and subtraction in the right order.
    int a1 = (int)number; // that worked fine

    but got no idea how to extract 2 numbers after '.'

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Double number formatting

    Use the other operators I mentioned: * and -
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 7
    Last Post: 04-06-2014, 02:47 PM
  2. String and number formatting
    By computerbum in forum New To Java
    Replies: 1
    Last Post: 04-27-2010, 05:06 PM
  3. Number formatting
    By gandalf5166 in forum New To Java
    Replies: 7
    Last Post: 03-26-2010, 02:54 AM
  4. Formatting a number to currency
    By Java Tip in forum java.text
    Replies: 0
    Last Post: 04-16-2008, 10:59 PM
  5. Correct Number formatting
    By paul in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 04:59 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
  •