Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 668
zslayton Avatar asked Jul 15 '09 20:07

zslayton


People also ask

How do you stop scientific notation when printing float values?

Summary: Use the string literal syntax f"{number:. nf}" to suppress the scientific notation of a number to its floating-point representation.

How do you avoid large numbers in scientific notation in R?

If you want to avoid scientific notation for a given number or a series of numbers, you can use the format() function by passing scientific = FALSE as an argument.

How do you print in scientific notation?

`e' This prints a number in scientific (exponential) notation. For example, printf "%4.3e", 1950 prints `1.950e+03', with a total of four significant figures of which three follow the decimal point. The `4.3' are modifiers, discussed below. `f' This prints a number in floating point notation.


1 Answers

> print(string.format("%18.0f",1247687475123456))

1247687475123456

like image 158
Doug Currie Avatar answered Oct 14 '22 00:10

Doug Currie