Working with Numbers

LiveCode does differentiate between text and numbers when you declare variables. It will treat a variable as number when you request. If the sring is not numeric , it will generate an error.

put "bird" into myNumber
 multiply myNumber by 2
 -- will generate an error
put "7" into myNumber
 multiply myNumber by 2
 -- will output 14

Operators

Operator: An operator specifies an operation to be performed on its operands. You are probably most familiar with arithmetic operators:

You can perform a wide variety of mathematical computations when working with numbers. LiveCode also follows the standard order of arithmetic operators.

LiveCode also allows you to:

put 15 into myNumber
subtract 5 from myNumber // myNumber is now equal to 10
divide myNumber by 2 // myNumber is now equal to 5
add 3 to myNumber // myNumber is now equal to 8
multitply myNumber by 2 // myNumber is now equal to 16

or there is the more standard approach using

put 10 * 2 into myNumber // myNumber = 20
 put "10" * "2" into myNumber // myNumber = 20

Mathematical Functions

  • coming soon

Rounding a number

round: Rounds a number up or down

put the round of 57.4 // yields 57
put round(76.9878,2) // rounds to two decimal places, outputs: 76.99

Leave a Reply