Float: Difference between revisions

From Computer Science Wiki
No edit summary
 
(One intermediate revision by the same user not shown)
Line 3: Line 3:
A float represents real numbers and is written with a decimal point dividing the integer and fractional parts. <ref>https://www.tutorialspoint.com/python/python_numbers.htm</ref>
A float represents real numbers and is written with a decimal point dividing the integer and fractional parts. <ref>https://www.tutorialspoint.com/python/python_numbers.htm</ref>


== Signed and unsigned ==
There is a deeper conversation about signed and unsigned numbers. You should know this:
* A signed number can be positive or negative
* An unsigned number can only be positive
A sign is basically an extra bit added to the binary number 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 ==  
== Difference between an int and a float ==  
Line 43: Line 35:
var a = -1234.65;  
var a = -1234.65;  
</syntaxhighlight>
</syntaxhighlight>
== Do you understand this? ==


== Standards ==  
== Standards ==  

Latest revision as of 11:00, 20 June 2019

Programming basics[1]

A float represents real numbers and is written with a decimal point dividing the integer and fractional parts. [2]


Difference between an int and a float[edit]

Integers and floats are two different kinds of numerical data. An integer (more commonly called an int) is a number without a decimal point. A float is a floating-point number, which means it is a number that has a decimal place. Floats are used when more precision is needed.[3]

Example[edit]

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;

Standards[edit]

  • Define the terms: variable, constant, operator, object.

References[edit]