How can I print a huge number in Lua without using scientific notation?

zslayton picture zslayton · Jul 15, 2009 · Viewed 15.9k times · Source

I'm dealing with timestamps in Lua showing the number of microseconds since the Epoch (e.g. "1247687475123456").

I would really like to be able to print that number in all its terrible glory, but Lua insists on printing it in scientific notation. I've scoured the available documentation about printing a formatted string, but the only available commands are "Print in scientific notation (%e/%E)" and "Automatically print in scientific notation if the number is very long (%g)". No options seem to be available to print the number in its normal form.

I realize that I could write a function that will take the original number, do some dividing by 10 and print the digits in a loop but that seems like an inelegant hassle. Surely there's some way of doing this that's built in to the language?

Answer

Doug Currie picture Doug Currie · Jul 15, 2009
> print(string.format("%18.0f",1247687475123456))

1247687475123456