Difference between revisions of "Set"

210 bytes added ,  13:11, 17 April 2006
m
no edit summary
imported>JOG
m
imported>JOG
m
Line 25: Line 25:




In integer divisions the remainder is truncated at the end of the operation:
'''Notes:'''


  set a to 9/5     ; will set "a" to 1
When using only numbers in the calculation, you need to use at least one decimal point to tell the game that you want to use floating point division, without a decimal point the remainder is truncated at the end of the division:
  set a to 10*9/5  ; will set "a" to 18
float a
  set a to 9/5   ; will set "a" to 1.000
  set a to 9.0/5  ; will set "a" to 1.800


 
When your variable is an integer and you want the result to be rounded you need to add 0.5:  
To accomplish correct rounding in integer divisions you need to add 0.5:
short a
 
  set a to 9.0/5+0.5 ; will set "a" to 2
  set a to 9/5+0.5 ; will set "a" to 2
  set a to 7.0/5+0.5 ; will set "a" to 1
  set a to 7/5+0.5 ; will set "a" to 1




Anonymous user