Results 1 to 3 of 3

Thread: Math in java

  1. #1
    blug is offline Member
    Join Date
    Oct 2010
    Posts
    26
    Rep Power
    0

    Default Math in java

    [I]Array[i].fee = ((Array.num / ((((double)number2 / 100) + 1)))) * (((double)number1 / 100) + 1);


    Isn't coming out the way I want it to...

    number2 = 10
    number1 = 15

    number2 and number1 are both int values, but I thought the typecasts I used would have helped.

    (((double)number2 / 100) + 1))) is coming out 1.0 when it should be 1.1

    (double)number1 / 100) + 1) is coming out as 1.1 when it should be 1.15

    Maybe I've done something wrong but I can't pick it, been sitting for an hour at this code.
    Last edited by blug; 11-22-2010 at 01:59 PM.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default

    Print the steps out separately instead of waiting until the whole expression is evaluated to see what's going on.

    Hint: what is being cast as a double in each of the following?
    Java Code:
    (double) number2 / 100
    Java Code:
    (double) (number2 / 100)
    Java Code:
    ((double) number2) / 100

  3. #3
    blug is offline Member
    Join Date
    Oct 2010
    Posts
    26
    Rep Power
    0

    Default

    ahh, I figured it out, actually wasn't my type casting.. just screwed up in one of my base methods <_<

Similar Threads

  1. Help with java math
    By gabrielfirestorm in forum New To Java
    Replies: 6
    Last Post: 10-25-2010, 01:54 PM
  2. Help need on math java program
    By zidangus in forum New To Java
    Replies: 27
    Last Post: 07-07-2010, 02:48 AM
  3. Java Math
    By levent in forum Java Tutorial
    Replies: 1
    Last Post: 05-12-2008, 09:03 AM
  4. java.lang.Math
    By eva in forum New To Java
    Replies: 2
    Last Post: 01-31-2008, 04:17 PM
  5. Help with math in java
    By fernando in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 06:05 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
  •