How to convert "-3" to an integer ?

M.E shared this question 2 years ago
Answered

I have some input boxes that are connected to a text variable. And then I convert the input to an integer by using the command; FromBase[ >>String<<, 10 ].

There is no problem as long as the string holds an integer >= 0.When the integer is negative, the command returns undefined. For example if I write:

FromBase[ "-3", 10 ]
How can I get GG to return a negative integer as in the example above ?


Best Answer

Comments (7)

photo
1

I always work with an earlier defined number n, using following script in the input box of a text variable:

SetValue(n, %0). This command assigns the typed text to the number n, no matter if it's positive or not.

chris

photo
1

Sorry, could you show how... ?

photo
1

see file added

chris

photo
1

Thanks a lot. :)

photo
photo
1

Nice, thanks.

photo
1

Can You please upload a file in which you have converted a text number into number ?

photo
© 2021 International GeoGebra Institute