mathsdkluadecimalcoronasdk

Finding if a variable has a decimal place / is a decimal number in Lua Corona SDK


I'm creating a math application, the question answers are stored in a variable called answer, i need a way to check if the answer has a decimal point in it, so for example say if the question generated is 4 divided by 3, i want to be able to check if the answer will have a decimal in it. Thank you.


Solution

  • Check out the math standard library. One way of checking if a number is an integer would be using the floor function:

    x == math.floor(x)
    

    Of course, this assumes x is a number and not a string.