lua-users home
lua-l archive

Re: Floats and %d

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


On Sat, Jul 18, 2015 at 11:29 AM, Rena <hyperhacker@gmail.com> wrote:
> In any case, I'm still wishing Lua would truncate for %d. I keep ending up
> with seemingly harmless UI code crashing with a "number has no integer
> representation" error, and ugly floor() littered everywhere. It reminds me
> of having to use tostring() with %s in earlier versions (a similar case
> which annoyed me as well). But perhaps I'm alone here...
You are not alone. After reflection, truncation for %d makes sense to me.
In Lua 5.2, %d would truncate. In Python also.
Is anyone willing to suggest that the error in Lua 5.3 has value?
Regarding:
http://lua-users.org/lists/lua-l/2014-12/msg00259.html
> string.format("%d", 2.7)
In this case, string.format does not have to convert 2.7 to an integer
(although it could). string.format in this case is converting a float
to a string, and the request for truncation is not hidden, it is
explicit in %d.
-Parke

AltStyle によって変換されたページ (->オリジナル) /