There are several ways to achieve it:
Using the unary plus operator:
var n = +str;
The Number
constructor:
var n = Number(str);
The parseFloat
function:
var n = parseFloat(str);
More Related Contents:
- Does JavaScript have double floating point number precision?
- When we using alert vs popup div tag? [closed]
- Turn if-else-if statement into switch statement in Javascript
- What is the purpose of the var keyword and when should I use it (or omit it)?
- How to return value from an asynchronous callback function? [duplicate]
- How to “properly” create a custom object in JavaScript?
- Preloading images with JavaScript
- Regex to match all instances not inside quotes
- Vanilla JavaScript Event Delegation
- JavaScript parser in JavaScript [closed]
- Jquery/Ajax call with timer
- How to convert JSON to CSV format and store in a variable
- Most efficient method of detecting/monitoring DOM changes?
- How to access accelerometer/gyroscope data from Javascript?
- Sort two arrays the same way
- toRad() Javascript function throwing error
- Passing variables through handlebars partial
- What does “return false;” do?
- How to subscribe to an event on a service in Angular2?
- How to swipe top down JQuery mobile
- javascript location.hash refreshing in IE
- How do I set default value of select box in angularjs
- d3 js – loading json without a http get
- Using javascript to download file as a.csv file
- How to send multipart/form-data form content by ajax (no jquery)?
- Using node.js’s File System functions from a browser
- jQuery: How to traverse / Iterate over a list of object
- React Router BrowserRouter leads to “404 Not Found – nginx ” error when going to subpage directly without through a home-page click
- Javascript – key / certificate from USB Token
- JQuery Modal Boxes and Iframe