
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How to get a decimal portion of a number with JavaScript?
With JavaScript, use the % operator to get the decimal portion of a number.
Example
You can try to run the following to get decimal portion −
<!DOCTYPE html> <html> <body> <script> var num1 = 5.3; var num2 = 4.2; var num3 = 8.6; document.write(num1 % 1); document.write("<br>"+num2 % 1); document.write("<br>"+num3 % 1); </script> </body> </html>
Output
0.2999999999999998 0.20000000000000018 0.5999999999999996
- Related Articles
- How to use JavaScript to replace a portion of string with another value?
- How to get the number of forms in a document with JavaScript?
- How to convert a decimal number to roman using JavaScript?
- Decimal count of a Number in JavaScript
- How to reverse a portion of an array in JavaScript?
- How to extract the hostname portion of a URL in JavaScript?
- How to convert a decimal number to a rational number with denominator to the power of 10?
- Reversing the bits of a decimal number and returning new decimal number in JavaScript
- How to get a string representation of a number in JavaScript?
- How to get a number value of a string in Javascript?
- How to get the cosine of a number in JavaScript?
- How to get the sine of a number in JavaScript?
- How to get the tangent of a number in JavaScript?
- How to get the length of a Number in JavaScript?
- How to use JavaScript to check if a number has a decimal place or it’s a whole number?

Advertisements