# Thread: Floating Point vs Integer

1. Member
Join Date
Oct 2012
Posts
4
Rep Power
0

## 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. Senior Member
Join Date
Oct 2012
Posts
166
Rep Power
2

## Re: Floating Point vs Integer

Ya and if you dealing with integers under 255 you can use bytes

3. Senior Member
Join Date
Jan 2013
Location
United States
Posts
2,691
Rep Power
4

## 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 05:05 AM.

4. Senior Member
Join Date
Jan 2013
Location
United States
Posts
2,691
Rep Power
4

## Re: Floating Point vs Integer

256 or 127 to -128 for signed bytes.

Regards,
Jim

#### Posting Permissions

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