Definition of Float in C, C++ and C#

A float variable can contain whole numbers and fractions

programmer at computer

alvarez / Getty Images 

Float is a shortened term for "floating point." By definition, it's a fundamental data type built into the compiler that's used to define numeric values with floating decimal points. C, C++, C# and many other programming languages recognize float as a data type. Other common data types include int and double.

The float type can represent values ranging from approximately 1.5 x 10-45 to 3.4 x 1038, with a precision — the limit of digits — of seven. Float can contain up to seven digits in total, not just following the decimal point — so, for example, 321.1234567 cannot be stored in float because it has 10 digits. If greater precision—more digits—is necessary, the double type is used.

Uses for Float

Float is used mostly in graphic libraries because of their extremely high demand for processing power. Because the range is smaller than in the double type, float has been the better choice when dealing with thousands or millions of floating-point numbers because of its speed. The advantage of float over double is negligible, however, because calculation speed has increased dramatically with new processors. Float is also used in situations that can tolerate rounding errors that occur due to the float precision of seven digits.

Currencies are another common use for float. Programmers can define the number of decimal places with additional parameters.

Float vs. Double and Int

Float and double are similar types. Float is a single-precision, 32-bit floating point data type; double is a double-precision, 64-bit floating point data type. The biggest differences are in precision and range.

Double: The double accommodates 15 to 16 digits, compared with float's seven. The range of double is 5.0 × 10−345 to 1.7 × 10308

Int: Int also deals with data, but it serves a different purpose. Numbers without fractional parts or any need for a decimal point can be used as int. The int type holds only whole numbers, but it takes up less space, the arithmetic is usually faster than with other types, and it uses caches and data transfer bandwidth more efficiently. 

Format
mla apa chicago
Your Citation
Bolton, David. "Definition of Float in C, C++ and C#." ThoughtCo, Apr. 5, 2023, thoughtco.com/definition-of-float-958293. Bolton, David. (2023, April 5). Definition of Float in C, C++ and C#. Retrieved from https://www.thoughtco.com/definition-of-float-958293 Bolton, David. "Definition of Float in C, C++ and C#." ThoughtCo. https://www.thoughtco.com/definition-of-float-958293 (accessed April 26, 2024).