Convert string to number

Asked

Viewed 1,171 times

1

How to convert string to number in rect?

I have a function that receives two parameters of type number(2,6), however, when sending them from one screen to another it is received as string.

How do I convert?

3 answers

3

  • how do I import the utilsModule?

  • 1

    If not installed on this link you have the instruction: https://www.npmjs.com/package/nativescript-utils If you are installed on this link you can do JS and Typescript. https://docs.nativescript.org/core-concepts/utils .

1


It worked for me like this:

Number(string);

1

Convert a string for number in React Native is the same problem to do this in Javascript, which is the language used by the framework. So just use the parseFloat():

parseFloat("123.45") // => 123.45 (Number)

Another more "exotic" way to convert is by using the plus sign:

+"123.45" // => 123.45

Browser other questions tagged

You are not signed in. Login or sign up in order to post.