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>
  
Click to view the demo

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>
  
Click to view the demo

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>
  
Click to view the demo

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>
  
Click to view the demo

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>
  
Click to view the demo

Scientific notation says take 1.234 and multiply it by 10-7.

Home 
  JavaScript Book 
    Language Basics  

Data Types:
  1. JavaScript Data Types
  2. typeof Operator
  3. The Undefined Type
  4. null Type
  5. null vs undefined
  6. Boolean Type
  7. Boolean() casting function
  8. The Literials of Number Type
  9. Octal Integer
  10. Hexadecimal
  11. Floating-Point Values
  12. Value range
  13. NaN
  14. Number Conversions:Number(), parseInt() and parseFloat()
  15. Number() function
  16. parseInt()
  17. parseFloat()
  18. The String Type
  19. String Literals and Escapes
  20. Get the String Length
  21. Converting to a String with toString() method
  22. Convert Number to String with radix
  23. Convert to String with String() casting function