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

Thread: Dividing numbers

  1. #1
    Pootis is offline Member
    Join Date
    Jul 2012
    Posts
    1
    Rep Power
    0

    Default Dividing numbers

    Right, I am kind of sorry for bothering you guys with a beginner question like this, but I cannot get over this relatively simple problem.

    So, I have this number, lets say, 12345678 and I want to turn it into number 12,3456789. How do I do that? 12345678/1000000 outputs 12.
    Last edited by Pootis; 07-31-2012 at 02:02 PM.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default Re: Dividing numbers

    That's how integer division works: it throws away any fraction (digits right of the decimal point); if at least one of the operands isn't an int, 'normal' division is applied; (hint 1000000.0 isn't an int).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,172
    Rep Power
    20

    Default Re: Dividing numbers

    1000000.0
    Without that it is treated as integer division, which gives an integer result.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,172
    Rep Power
    20

    Default Re: Dividing numbers

    I knew I should have refreshed the page....
    JosAH likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Dividing in java
    By poop in forum New To Java
    Replies: 4
    Last Post: 05-30-2011, 08:56 AM
  2. Dividing in Java
    By hawaiifiver in forum New To Java
    Replies: 19
    Last Post: 03-11-2011, 12:09 PM
  3. Dividing 3 items, please help.
    By Quizzle23 in forum New To Java
    Replies: 18
    Last Post: 02-24-2011, 07:42 AM
  4. Replies: 2
    Last Post: 10-28-2010, 02:56 PM
  5. Dividing numbers with remainders showing
    By denisdoherty in forum New To Java
    Replies: 16
    Last Post: 04-24-2008, 06:39 PM

Posting Permissions

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