Convert String to Integer Float Number in React Native

Hello friends, In today’s tutorial we would learn about 3 Math functions comes inbuilt in JavaScript in react native Number(), parseInt() and parseFloat(). They all are used to convert string to number format in react native. But they have different approaches. I’ll explain them one by one below. So in this tutorial we would learn about Convert String to Integer Float Number in React Native.

Explanation :-

  1. Number() :- The number function is used to convert all the JavaScript react native variables to number format.
  2. parseInt() :- The parseInt function is used to convert a String to new number, It does support spaces but only first number will be returned.
  3. parseFloat() :- The parseFloat function is used to convert String to a float number. It also supports spaces and only first number will be returned.

Contents in this project Convert String to Integer Float Number in React Native :-

1. Open your project’s main App.js file and import StyleSheet, Button and SafeAreaView component.

2. Creating our main App component.

3. Creating 6 types of variables with different different values.

4. Creating a function named as toNumber(). In this function we would apply all 3 functions Number(), parseInt() and parseFloat() one by one on all these variables. So you can see how they react on each different type of string.

5. Creating return() block, Here we would make 1 Button component and call above function on button click event.

6. Creating Style.

7. Complete Source Code for App.js File :-

Screenshot :-

Leave a Reply

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