const data = Number('48155'); console.log(data);
Now, we need to start the node.js server using this flowing command.
Node server count decimal as well.
An integer is a wrapper object and it can perform many operations. If we use the constructor (
new Number("14785")) so it will return us a Number object instead of a number value.
The parseInt() function parse a string and return an integer (a whole number). but it will Only the first number in the string is returned!
let text = '21px'; let integer = parseInt(text, 10); console.log(integer);
it will return log the 21 value.
The parseFloat() function is quite different it converts a string into a point number (a number with decimal points). You can even pass in strings with random text in them.
// server.js let text = '3.14pie'; let integer = parseFloat(text, 10); console.log(integer);
+ Unary Operator
To use Unary Operator + before the string. unary plus (+) is used when the string is already in the form of an integer.
// server.js let x = 6+"1000"; console.log(x);
It's return output is 61000.
#math.floor is Similar to the + unary operator, but the difference is it returns the integer part.
// server.js let floor = Math.floor("1000.51"); console.log(floor);
Mostly #math.floor() used when you want to change the float value to an integer then it might help you.
The answer of above will be 1000.
This all three methods work fine in all modern browsers, and IE6 and up.
Hello, My Name is Brijpal Sharma. I am a Web Developer, Professional Blogger and Digital Marketer from India. I am the founder of Codermen. I started this blog to help web developers & bloggers by providing easy and best tutorials, articles and offers for web developers and bloggers...
You must be logged in to post a comment.