How to Remove the Decimal Part of a Number in JavaScript ? Last Updated : 29 Jan, 2024 Comments Improve Suggest changes Like Article Like Report The decimal portion of a number in JavaScript can be removed through various methods, including the Math. trunc( ) method, Math. floor( ) method, Math. ceil( ) method, and Math. round( ) method. SyntaxMath.trunc(11.5) // Output: 11Math.floor(12.5) // Output: 12Math.ceil(15.5) // Output: 15Math.round(-20.5) // Output: -20Table of Content Using Math.trunc() MethodUsing Math.floor() MethodUsing Math.ceil() MethodUsing Math.round() MethodUsing Math.trunc() MethodThe Javascript Math. trunc() method is used to return the integer part of a floating-point number by removing the fractional digits. Example: The below code illustrates how to remove the decimal part of a number Using the Math. trunc( ) Method. JavaScript console.log(Math.trunc(15.80)); console.log(Math.trunc(0.12)); console.log(Math.trunc(-10.80)); Output: 150-10Using Math.floor() MethodMath.floor() method is used to round off the number to its nearest integer and returns the smallest integer greater than or equal to the given number. Example: The below code illustrates how to remove the decimal part of a number Using Math.floor() Method. JavaScript console.log(Math.floor(-12.10)); console.log(Math.floor(0.79)); Output: -130Using Math.ceil() MethodMath.ceil() method is used to return the smallest integer greater than or equal to a given number. Example: The below code illustrates how to remove the decimal part of a number Using Math.ceil() Method. JavaScript console.log(Math.ceil(32.80)); console.log(Math.ceil(0.80)); console.log(Math.ceil(-29.70)); Output: 331-29Using Math.round() MethodMath.round() method is used to round a number to its nearest integer. If the fractional part of the number is greater than or equal to .5, the argument is rounded to the next higher integer. Example: The below code illustrates how to remove the decimal part of a number. JavaScript console.log(Math.round(42.80)); console.log(Math.round(0.80)); console.log(Math.round(-89.70)); Output: 431-90 Comment More infoAdvertise with us Next Article How to Remove the Decimal Part of a Number in JavaScript ? S shivanigupta18rk Follow Improve Article Tags : JavaScript Web Technologies javascript-math JavaScript-Questions Similar Reads How to get decimal portion of a number using JavaScript ? Given a float number, The task is to separate the number into integer and decimal parts using JavaScript. For example, a value of 15.6 would be split into two numbers, i.e. 15 and 0.6 Here are a few methods discussed. These are the following methods: Table of Content Javascript String split() Method 3 min read How to Format a Number with Two Decimals in JavaScript? In javascript, formatting numbers to a fixed number of decimal places is a common requirement, particularly in financial calculations, statistical data presentations, and to show in user interfaces. In this article we will explore different approaches to format a number with two decimals in JavaScri 2 min read How to Validate Decimal Numbers in JavaScript ? Validating user input is an essential aspect of Web Development. As a developer, when we are playing with the numeric inputs provided by the end-user, it is quite important to ensure that the input provided by the user is in the correct format. We can use the regular expression to Validate Decimal N 2 min read How to Restrict Input to Numbers and Decimals in JavaScript? Restricting an input box to allow only numbers and decimal points involves setting up validation rules that ensure users can only enter numerical values and decimal separators. This helps maintain data integrity and prevents invalid entries in forms or user input fields.Below are the approaches to r 3 min read Round off a number upto 2 decimal place using JavaScript A number can be rounded off to 2 decimal places using 2 approaches: Method 1: Using the toFixed() method The toFixed() method is used to return a string representation of a number upto a certain number of digits after the decimal point. The number is rounded and the fractional part is padded if nece 2 min read How to print a number with commas as thousands separators in JavaScript? Method 1: Using Intl.NumberFormat() The Intl.NumberFormat() object is used to represent numbers in language-sensitive formatting. It can be used to represent currency or percentages according to the locale specified.The locales parameter of this object is used to specify the format of the number. Th 2 min read How to convert decimal to octal in JavaScript ? In this article, we are given a number and the task is to convert the number from decimal to octal. This can be done by using number.toString(8) method. It takes the parameter which is the base of the converted string. In this case, the base will be 8. Syntax: number.toString(8) The below examples s 2 min read How to format numbers as currency string in JavaScript ? A number, represented as monetary value, creates an impact and becomes much more readable, and that's the reason behind formatting a number as currency. For example, a number, let's say 100000 when represented as $100,000.00 it becomes pretty much understood that it represents a monetary value, and 3 min read How to Convert a Float Number to the Whole Number in JavaScript? Given a float number and the task is to convert a float number to a whole number using JavaScript. Below are various methods to convert float numbers to whole numbers in JavaScript:Table of ContentMath.floor (floating argument)Math.ceil (floating argument) Math.round (floating argument)Math.trunc (f 4 min read Convert a String to Number in JavaScript To convert a string to number in JavaScript, various methods such as the Number() function, parseInt(), or parseFloat() can be used. These functions allow to convert string representations of numbers into actual numerical values, enabling arithmetic operations and comparisons.Below are the approache 4 min read Like