lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


>Can you set the decimal precision in Lua?

Nope. I used inlined assembler once but it caused problems with other libraries that'd reset it or behaved strangely so it's best to leave it alone.

Wrt to loops and similar logic you shouldn't use fractional values at all, in whatever language (yes, a Lua "value" is a double but its mantissa is larger than a 32-bit integer).

If you /must/:
- multiply consts so there's no more fractional part (in the previous example mul start/end/step by 10)
- use math.floor()
- use <,<=, >, >= comparison operators

cheers,

-- p