Convert Text Input to int/ How to make numeric input that can be used for Math

Has there been any improvements because I am having the same problem

@akul.whitehatjruwh When you write “I am having the same problem” it’s really hard to know what exactly is happening in your project. Can you provide some details? A screenshot of the blocks you’re using would be helpful.



image
these are the pics and it shows NaN.

with all numbers

Well I got the solution to the problem…Sorry if I wasted your time

1 Like

You can convert the text input to a numeric value by adding 0 to it or multiplying it by 1 then apply any mathematical operation on it.

1 Like

can you tell that it will help other users

I suspected – and @muneer confirmed – that you have to first convert the text value to a numeric value by adding 0 or multiplying by 1 and then you can use more advanced math functions like square/exponential power.

3 Likes

Hi tatiang, muneer

I am having the NaN issues so tried the conversation by adding zero which has now resulted in the updated value in the google sheet to be stored as value. As a test, I have a label that displays the value that I am trying to update and that still shows as NaN. The cells have an original value that was created via thunkable and it is stored in the sheet as a number. the original value displays correctly as a number so the error is just from the update any ideas?

1 Like

a NaN is a result of the attempt of converting none integers to numbers. If the value is formatted to have a leading character or symbol then you need to get rid of it first. The unusual number separators are also considered as none integers and would cause a NaN error if found first.

I created a small block to test the value given.

This is the result
image

The value uses the math block to set the starting value to 500 and is declared as a number using the math block this is updated to G-sheets where is displays as a number of 500 I am able to use it as a number in sheets it’s then stored as a variable in the app and later used in addition I have done as suggested and added 0 to the values to be updated but no joy. The value is not used as text at any point in the app. Any other ideas?

2 Likes

Can you share a screenshot of the codes that brings this error?


I have played around a lot so its a bit messy. It updates but with NaN

1 Like

What is the initial value of stored variable leaderboard_score_total?
This is initialized as a stored variable and sets initially to Null and would not accept any kind of mathematical operation unless it is first reset to ZERO or any other value than Null.

You need a code block like this either on the start/open of the screen or before you do your maths.

image

1 Like

Brilliant! it’s now showing values. I had set it to 500 on sign up but it seems it needs to go to zero first. but looks like this is working now. Thanks so much.

1 Like

The easiest way is to set the keyboard type to numeric


Screen Shot 2021-07-20 at 10.31.21 PM

1 Like

Thank you for your suggestion @suhanibansal , however, in this case the value is retrieved from a Google sheet row and the keyboard settings will have no effect.