Results 1 to 5 of 5
  1. #1
    its_crawford is offline Member
    Join Date
    Jun 2010
    Posts
    2
    Rep Power
    0

    Default really quick question for beginner

    hey there, im making a little program that converts celcius to farenheit blah blah not important

    heres the situation:

    celcius = c
    farenheit = f
    (bot c and f are doubles)


    c = (5/9) * (f-32)


    weird thing is using that equation doesnt work and my value for C will be zero


    i know it a problem with 5/9 because if i use someone like 10/5 itll work just fine. so whats the problem with 5/9? is division whacky in java or something?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    You are stumbling against int division. You see an int divided by an int will result in an int, with rounding and all. Convert one to a double:



    c = (5.0/9.0) * (f-32)

  3. #3
    its_crawford is offline Member
    Join Date
    Jun 2010
    Posts
    2
    Rep Power
    0

    Default

    mmmother F! so simple! thanks!

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    You're quite welcome. Welcome to the forum by the way!

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by Fubarable View Post
    You are stumbling against int division. You see an int divided by an int will result in an int, with rounding and all. Convert one to a double:



    c = (5.0/9.0) * (f-32)
    Assign 5/9 into a local int variable and see what's the result. Situations like this you can do that.

Similar Threads

  1. Really quick question
    By shadycharacter in forum New To Java
    Replies: 2
    Last Post: 04-22-2010, 10:06 PM
  2. Quick question
    By sAntA199 in forum New To Java
    Replies: 2
    Last Post: 12-09-2009, 03:01 AM
  3. quick question
    By vouslavous in forum Java Applets
    Replies: 4
    Last Post: 04-24-2009, 08:35 PM
  4. Hello everyone! quick question.
    By irishhokie in forum New To Java
    Replies: 5
    Last Post: 04-03-2009, 04:13 AM
  5. Quick Question
    By Spenc in forum New To Java
    Replies: 3
    Last Post: 09-22-2008, 02:26 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
  •