Floats

=Floats=

A float or floating point number is a computer representation of a decimal. The name refers to the fact that the decimal point can "float" or be placed anywhere relative to the significant digits of the number. Its basically the computer representation of scientific notation. There is also a data type called the double which does the same thing but it takes up more memory. If you want to be as precise as possible use a double otherwise, just use a float to save some memory.

In C++
Initializing a float in C++ is just like initializing an integer but with the decimal place appended to the end. code format="cpp" main{ float myFloat = 0.2; double moarFloat = 11111.5487488888; } code

In Java
Initializing a float in Java is slightly different. In java you must specify if you want a number to be a float(small) or double(large) by simply adding 'f' to the end of the number if you want a float. Also just like an integer, Java provides a class called BigDecimal if you need to get really really precise. code format="java" import java.math.BigDecimal;

public class IntDemo{ public static void main(String[] args){ float myFloat = 0.5f; //notice the f

double moarFloat = 1.55; //no need for an f here

BigDecimal myDecimal = new BigDecimal("99999.9999999999999999999999999"); } } code