How do I change math equation from text variable to number

0 favourites
  • 3 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Hello!

    If I have a text variable that looks for example like this: "5+7+2*8", is there any way of it calculating the values of that, and then making the answer a number variable? So in the end I would get a number variable with the value of 28.

    Any help would be greatly appreciated

    Regards,

    Kriss

  • Browser.ExecJS("eval('" & yourString & "');")

    I think that will return a string with the evaluated value. And then you can do:

    Browser.ExecJS("!isNaN(""" & value & """);")=1?float(value)%1<>0?float(value):int(value):value

    which will give you it as either a float,int,or string if it isn't NaN.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Browser.ExecJS("eval('" & yourString & "');")

    I think that will return a string with the evaluated value. And then you can do:

    Browser.ExecJS("!isNaN(""" & value & """);")=1?float(value)%1<>0?float(value):int(value):value

    which will give you it as either a float,int,or string if it isn't NaN.

    This was extremely helpful, thank you so much! It wouldve taken me ages to research that. Thanks a lot

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)