Results 1 to 4 of 4
  1. #1
    CaleyM is offline Member
    Join Date
    Oct 2012
    Posts
    4
    Rep Power
    0

    Default Floating Point vs Integer

    I just read about how the data is stored in float. It seems like the range would be greater because it stores scientific notation rather than plain value, whilst integer arithmetic performance is better. So my conclusion is that float should be used to store bigger values and integer should be used for speed when values are smaller. As an example, I want to have cubic volumes ranging from about a handful to cargo ship. So float would be necessary for that. I could use int for money as long as the accounts won't go above ~4b. Am I making sense?

  2. #2
    Daryn is offline Senior Member
    Join Date
    Oct 2012
    Posts
    176
    Rep Power
    2

    Default Re: Floating Point vs Integer

    Ya and if you dealing with integers under 255 you can use bytes
    With the right know how, anything is possible

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,501
    Rep Power
    5

    Default Re: Floating Point vs Integer

    Ints are faster simply because the instructions to do integer operations are faster. Floats and doubles require more cycles. Ints are used when you don't need decimals. Doubles are used for floating point arithmetic. They work fine for some values but for money, you should use BigDecimal or ints and maintain the money is cents (US currency). Otherwise, rounding error will occur. Also doubles have a larger exponents and mantissas than floats. I presume when you said you read about it you checked out IEEE 754.

    Also, ints are 32 bits wide which, if unsigned, would be about 4.3 billion. But the high order bit for both floating point values and integers is the sign bit. So the largest positive value an integer can store is (2^31)-1 where ^ is exponentiation.

    Regards,
    Jim
    Last edited by jim829; 01-31-2014 at 04:05 AM.
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,501
    Rep Power
    5

    Default Re: Floating Point vs Integer

    256 or 127 to -128 for signed bytes.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. floating point errors
    By mikele83 in forum New To Java
    Replies: 8
    Last Post: 04-24-2011, 03:52 PM
  2. Displaying floating point value
    By NuxlyStardust in forum New To Java
    Replies: 11
    Last Post: 04-14-2011, 06:40 PM
  3. Floating point inaccuracy
    By Aga in forum Advanced Java
    Replies: 6
    Last Post: 02-04-2011, 05:07 AM
  4. if it is floating point number
    By Stephen Douglas in forum New To Java
    Replies: 26
    Last Post: 07-06-2010, 09:17 AM
  5. number of floating point
    By mohammad8065 in forum Advanced Java
    Replies: 5
    Last Post: 12-28-2008, 09:41 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
  •