Float

From Computer Science Wiki
Jump to: navigation, search
Programming basics[1]

A float represents real numbers and is written with a decimal point dividing the integerA natural number, a negative of a natural number, or zero. and fractional parts. [2]

Signed and unsigned

There is a deeper conversation about signed and unsigned numbers. You should know this:

  • A signed numberA unit of abstract mathematical system subject to the laws of arithmetic. can be positive or negative
  • An unsigned numberA unit of abstract mathematical system subject to the laws of arithmetic. can only be positive

A sign is basically an extra bit added to the binary numberA unit of abstract mathematical system subject to the laws of arithmetic. indicating it is negative or positive. There is more to this, but that is what you should know.

Difference between an int and a float

Integers and floats are two different kinds of numerical data. An integerA natural number, a negative of a natural number, or zero. (more commonly called an int) is a numberA unit of abstract mathematical system subject to the laws of arithmetic. without a decimal point. A float is a floating-point numberA unit of abstract mathematical system subject to the laws of arithmetic., which means it is a numberA unit of abstract mathematical system subject to the laws of arithmetic. that has a decimal place. Floats are used when more precision is needed.[3]

Example

In PHP: You will remember PHP isn't a strictly typed language (although it can be set to be).

<?php
$a = 1234.65; // decimal number
$a = -1234.54; // a negative number
?>

In Python:

# decimal number:
a = 1234.65
# a negative number:
a = -1234.65

In Javascript:

// decimal number:
var a = 1234.65; 
// a negative number:
var a = -1234.65;

Do you understand this?

Standards

  • DefineGive the precise meaning of a word, phrase, concept or physical quantity. the terms: variable, constant, operator, object.

References