How can I convert a scientific notation to an integer?

Hello! I am making code for my simulator, and I need to make scripts that can handle really large values.

I need to find a way to convert a scientific notation (ex: 4.3462346e+14) to an integer (I have no idea what that number would be as an integer, but it would look like this: 4434534654634563456)

I am trying to use string.format, but I am not sure how one would set it up

string.format(tostring(tonumber(player.privstats.Cash.Value) + amount),"%c") -- I need to input an integer and add an amount. However, if the added amount throws the integer into a scientific notation, I need to be able to convert it back. As you can see, I tried string.format but that does not seem to work.

Thank You For Your Time :slight_smile:

1 Like

Pretty sure you can just do string.format("%f", 4.3462346e+14) and it’ll return 43462346.0000000.

2 Likes

is 4.346234e+14 equal to 43.46 Million?

huh. I guess it is. Ty. What does “%f” mean?

No idea, I just googled how to convert scientific notation to an integer in lua once and that’s what came up.

It’s short for “float”, which is what some other languages store a decimal number as. %i would also work if you want to force it to display as an integer. Here’s a list of formatter codes: (Unsure how complete this is)

A simple directive is the character % plus a letter that tells how to format the argument: d for a decimal number, x for hexadecimal, o for octal, f for a floating-point number, s for strings, plus other variants. Between the % and the letter, a directive can include other options, which control the details of the format, such as the number of decimal digits of a floating-point number:

4 Likes