| Class 1, Part 2 | 
Intro to Java 30-IT-396 | 
  | 
Floating Point Types
- 
Numbers with fractional (decimal) values.
 
- 
Two types:
 
| Primitive Type | 
Size | 
Range | 
| float | 
4 bytes | 
+/- 3.40282347E + 38F | 
| double | 
8 bytes | 
+/- 1.79769313486231570E+308 | 
- 
float is probably the most common.
 
- 
double is sometimes called double-precision.
 
- 
Consider yourself warned:
 
- 
These two types use floating point arithmetic (FPA).  FPA values speed
and efficiency over 100% accuracy.  Thus, occasionally the results
of operations may be off by a fraction.  This isn't a big deal for
some applications, but when dealing with currency, it can creep up and
cause a headache.  I speak from experience!
 
- 
If you require 100% accuracy, use the BigDecimal object.  It is slower,
but it is much more accurate.
 
- 
There are three special types:
 
- 
NaN: not a number.  Where have we seen this before?  You can
test with Double.isNaN();
 
- 
POSITIVE_INFINITY: a positive number divided by 0.
 
- 
NEGATIVE_INFINITY: a negative number divided by 0.
 
 char, boolean
Created by:  Brandan
Jones January 4, 2002