Hi, bit of a maths question.
What would the expression be to constrain a number to one decimal place, so rather than 4.65, it would just be 4.6?
thanks [import]uid: 8699 topic_id: 5844 reply_id: 305844[/import]
Hi, bit of a maths question.
What would the expression be to constrain a number to one decimal place, so rather than 4.65, it would just be 4.6?
thanks [import]uid: 8699 topic_id: 5844 reply_id: 305844[/import]
[lua]local number1 = 4.63
local number2 = tonumber(string.format("%.1f",number1))
print(number2 + 1) – => 5.6[/lua]
you can actually remove the tonumber(), since +1 in the third line would convert it back to a number anyway
[lua]local number1 = 4.63
local number2 = string.format("%.1f",number1)
print(type(number2)) – => “string”
number2 = number2 + 1 --> + operation forces a number type
print(type(number2)) – => “number”
print(number2)[/lua] [import]uid: 6645 topic_id: 5844 reply_id: 20043[/import]
Thanks for the info and code, I will give it a try!
Gary [import]uid: 8699 topic_id: 5844 reply_id: 20158[/import]