504 posts
Posted 02 July 2013 - 06:53 PM
Hey
i am having a doulbe number like 14.25, which gets math.ceil()ed and it is 15.0
The ".0" after the 15 does get printed now, which i dont want.
How get i rid of this?
Sincerly
unobtanium
375 posts
Location
USA
Posted 02 July 2013 - 07:43 PM
I just typed print(math.ceil(14.25)) in the Lua interpreter and 15 was printed. What context does this happen in?
1688 posts
Location
'MURICA
Posted 02 July 2013 - 07:55 PM
Try using a format string.
print(string.format('%d', someNumber))
Or,
print(('%d'):format(someNumber))
They both do the same thing, just with slightly different syntax.
7508 posts
Location
Australia
Posted 02 July 2013 - 08:24 PM
Try using a format string.
print(string.format('%d', someNumber))
I'd suggest using %i not %d … %d is very likely that in this context it will keep the .0 as 'd' is Double, so use 'i' for Integer…
1604 posts
Posted 02 July 2013 - 08:56 PM
Try using a format string.
print(string.format('%d', someNumber))
I'd suggest using %i not %d … %d is very likely that in this context it will keep the .0 as 'd' is Double, so use 'i' for Integer…
Nope, "%d" is for integers too. "%f", "%e" and "%g" are for float/double.
This
printf reference lists all the formats you can use. string.format uses printf (in the C version), so this should be the same for CC lua.