Hello and welcome to our community! Is this your first visit?
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
    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. #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Saskatoon, Saskatchewan
    Thanked 2,668 Times in 2,637 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'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


Posting Permissions

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