Decimals in Lua?

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
rylleman
Posts: 750
Joined: Tue Feb 15, 2005 5:22 pm
Location: sweden
Contact:

Decimals in Lua?

Post by rylleman »

I'm trying to write my first script in Lua, going well except for one little thing.

To see if a value is changed I use ~= between the old and the new value. Problem is that Moho round off the value so the condition gets false when it shouldn't be, is there a way to compare two values only down to the first 3 decimals with the expression ~=?
User avatar
rylleman
Posts: 750
Joined: Tue Feb 15, 2005 5:22 pm
Location: sweden
Contact:

Post by rylleman »

Never mind, I figured it out.

if string.format("%.4f", newVal.x) ~= string.format("%.4f", oldVal.x) then
Post Reply