Converting and using a string as a number in react apps. Javascript string to number conversion.
How to convert string to a number?
Using the Number Object for conversion
We can make use of the Number object to convert a string to a number.
const amount = Number(inputValue); const convenienceFee = Number('20');
TypeScript React Example
Example Code with typescript type checking for string and number in react app.
const inputValue : string = "250" const amount : number = Number(inputValue); const convenienceFee : number = Number('20');
Example Code String to Number conversion React JavaScript:
const handleInput (event) => { const amount = Number(event.target.value); console.log("Amount:" + amount ); }