lua-users home
lua-l archive

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


The issue is that computers store floating point numbers as a binary representation, and the binary representation cannot always represent exactly numbers that are finite in decimal. This is why 0.1 + 0.1 + 0.1 does not equal 0.3. If you absolutely want to represent time as a numeric value, use integers (such as 1121 for 11:21), which are guaranteed to be exact.

On Wed, Oct 19, 2016 at 3:45 PM Laurent FAILLIE <l_faillie@yahoo.com> wrote:
Ok, thanks a lot.
It's working.
But is it a way to "force" the precision of stored value ?




Le Mercredi 19 octobre 2016 12h39, Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> a écrit :


> As you can see, an entry for 11.21 exists but is not found.I suspect a (deep) rounding issue as the argument come from a calculation ... but is only a guess.


If the number comes from a calculation, then rounding is definitely a suspect,
especially if the result is 11.21.

I suggest you store the keys as strings instead of numbers, using something
like string.format("%.2f",x) to convert numbers to strings.