1. Technology
Send to a Friend via Email

Float

By

Businessman using a laptop in an office
Eric Audras/ONOKY/Getty Images
Definition:

A float is a Java data type which can store floating point numbers (i.e., numbers that can have a fractional part). Only 4 bytes are used to store float numbers giving a value range of -3.4028235E+38 to 3.4028235E+38.

A problem with the float (and double) data type is it suffers from rounding errors:

float rounding = 0.9f - 0.11f;
System.out.println(rounding);

gives the output of:

0.78999996

Use the BigDecimal class for precise calculations.

Note: float data types are not used unless memory is an issue and an application needs to store a lot of fractional numbers. The double is the default data type to use for storing fractional numbers.

Glossary:

# A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Related Video
Create Bullet, Number, and Definition Lists in HTML
Export Data From an Excel Sheet to a Word Document
  1. About.com
  2. Technology
  3. Java
  4. Java Glossary
  5. F
  6. Definition for the Java Term: Float

©2014 About.com. All rights reserved.