Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    May 2011
    Posts
    37
    Thanks
    3
    Thanked 0 Times in 0 Posts

    I need help with Java Maths

    Please can any one help me with this problem? I want to devide 11 by 365 (11/365) but when I try to do that with data type double I get the anser to be zero. Like double myValue=11/365;
    I get the answer to be myValue=0.0 instead of 0.030136986...

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    You're dividing an int by an int, and that is cast into a double. Integer 0 is cast to double 0.0. Convert one or both to doubles by using 11.0/365.0, or if they're variables cast them to float/double during the operation.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

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