lua-users home
lua-l archive

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


On Wed, Feb 10, 2016 at 11:50 AM, Coda Highland <chighland@gmail.com> wrote:
>
> On Feb 10, 2016 8:46 AM, "Daniel Silverstone" <dsilvers@digital-scurf.org>
> wrote:
>>
>> On Wed, Feb 10, 2016 at 17:26:24 +0100, Marc Balmer wrote:
>> > We switched from Lua 5.2 to Lua 5.3 and suddenly a seemingly small
>> > change in Lua's number formatting is hitting us really hard:
>> >
>> > Before 5.2, a number value of 41.0 would produce a string of '41'.
>> > After 5.3, it produces '41.0':
>>
>> Time to start using string.format("%u", ...) ?
>>
>> D.
>>
>> --
>> Daniel Silverstone                         http://www.digital-scurf.org/
>> PGP mail accepted and encouraged.            Key Id: 3CCE BABE 206C 3B69
>>
>
> That only works if you know the value is an integer. If it's not, then
> you're losing data. There operation you want is probably more like s/\.0$//
> than %u.

In Lua 5.3, %u will produce an error if the number is not
representable as an integer without loss of data:

$ lua
Lua 5.3.2  Copyright (C) 1994-2015 Lua.org, PUC-Rio
> string.format("%u", 1.1)
stdin:1: bad argument #2 to 'format' (number has no integer representation)
stack traceback:
        [C]: in function 'string.format'
        stdin:1: in main chunk
        [C]: in ?

-- 
Patrick Donnelly