As I will cover this Post with live Working example to develop string to number conversion, so the string to number conversion for this example is following below.
const data = Number('9898256'); console.log(data);
1: Using #parseInt()
E-junkie: Sell digital downloads online
E-junkie Provides a Copy-paste buy-now, and cart buttons for selling downloads, codes and tangible products on any website, blog, social media, email and messenger!
parse a string and return an integer (a whole number)
let data_value = '21px'; let results = parseInt(data_value, 10); console.log(results);
2: Using #parseFloat()
converts a string into a point number
// main.js let data_value = '3.14pie'; let results = parseFloat(data_value, 10); console.log(results);
3: Using + Unary Operator
use Unary Operator + before the string
// main.js let data = 6+"1000"; console.log(data); //It's return output is 61000.
4: Using #Math.floor()
same + unary operator
// main.js let data_floor = Math.floor("1000.51"); console.log(data_floor);
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.