JavaScript Numeric Operation

JavaScript Numeric Operation

We have already performed several arithmetic operations on numbers till now. Apart from this, JavaScript provides following operations on numbers:

Operation Description Example
toString() It returns numbers as strings. var x = 123;

var y = x.toString();

Output: “123”

toFixed() It rounds a number to a given number of digits and returns it in the form of a string. var x = 9.656;

x.toFixed(0); Output: 10

x.toFixed(2); Output: 9.66

valueOf() It returns the value of a variable var x = 123;


Output: 123

Number() It converts variables into a number. It can also convert a date into a number. Number(new Date(“2019-05-01”));

Output: 1556668800000

parseInt() It parses a string and returns a whole number. It returns only the first number. parseInt(“10.33”);

Output: 10


  • Barry Allen

    A Full Stack Developer with 10+ years of experience in different domain including SAP, Blockchain, AI and Web Development.

    View all posts


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.