Floating-Point Values
A floating-point value literal must have a decimal point and at least one number after the decimal point.
<!DOCTYPE html>
<html>
<head>
<title>Number Example</title>
<script type="text/javascript">
var floatNum = 1.2;
document.writeln(floatNum);
</script>
</head>
<body>
</body>
</html>
If there is no digit after the decimal point, the number becomes an integer.
<!DOCTYPE html>
<html>
<head>
<title>Number Example</title>
<script type="text/javascript">
var floatNum = 1.;
document.writeln(floatNum); // an integer
</script>
</head>
<body>
</body>
</html>
If the number being represented is a whole number, it is converted into an integer:
<!DOCTYPE html>
<html>
<head>
<title>Number Example</title>
<script type="text/javascript">
var floatNum = 1.0;
document.writeln(floatNum);
</script>
</head>
<body>
</body>
</html>
Scientific notation
<!DOCTYPE html>
<html>
<head>
<title>Number Example</title>
<script type="text/javascript">
var floatNum = 1.234e7;
document.writeln(floatNum);
</script>
</head>
<body>
</body>
</html>
Scientific notation says take 1.234 and multiply it by 107.
<!DOCTYPE html>
<html>
<head>
<title>Number Example</title>
<script type="text/javascript">
var floatNum = 1.234e-7;
document.writeln(floatNum);
</script>
</head>
<body>
</body>
</html>
Scientific notation says take 1.234 and multiply it by 10-7.
Home
JavaScript Book
Language Basics
JavaScript Book
Language Basics
Data Types:
- JavaScript Data Types
- typeof Operator
- The Undefined Type
- null Type
- null vs undefined
- Boolean Type
- Boolean() casting function
- The Literials of Number Type
- Octal Integer
- Hexadecimal
- Floating-Point Values
- Value range
- NaN
- Number Conversions:Number(), parseInt() and parseFloat()
- Number() function
- parseInt()
- parseFloat()
- The String Type
- String Literals and Escapes
- Get the String Length
- Converting to a String with toString() method
- Convert Number to String with radix
- Convert to String with String() casting function