# Floating Point vs Integer

• 01-31-2014, 04:42 AM
CaleyM
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?
• 01-31-2014, 04:48 AM
Daryn
Re: Floating Point vs Integer
Ya and if you dealing with integers under 255 you can use bytes
• 01-31-2014, 04:54 AM
jim829
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
• 01-31-2014, 04:55 AM
jim829
Re: Floating Point vs Integer
256 or 127 to -128 for signed bytes.

Regards,
Jim