How to convert scientific notation to a rounded whole number

I want to display a big number on a text label, however it gets displayed in scientific notation. I’ve tried using string format but it just gives me a lot of zeroes at the end. like 42343565.0000000 something like that.

text.Text = string.format("%f",exp.Value).." / "..string.format("%f",expNeeded)

So when using string.format the “%f” part is the format to follow. So for you the float probably has a small decimal number on the end of it e.g. 42343565.00000000001. To fix this you can use different formatting types:

c = Integer
d or i = Integer with Decimal Representation e.g. 3.24 = 324
e or E = Scientific Float Notation
f = float

There are more, if you want to see them, here’s the link: Strings | Documentation - Roblox Creator Hub

For your purpose I think you want this:

text.Text = string.format("%c",exp.Value).." / "..string.format("%c",expNeeded)

Hope this helps :slightly_smiling_face:

The %f format have a precision of 6 decimal places by default, you can use %.0f so it’ll format it with no fractional digits (rounded).

Floats (double precision in this case) will always represent an integer without any fractional value exactly if it’s under 2 ** 53 (9007199254740992) (for double precision).
There would be no reason to have few trailing zeroes when formatted if it has a very small fractional number than if it doesn’t.

%c will format to an ASCII character, not as a base 10 integer.

3.24 gets truncated to 3, not 324.

2 Likes

You are correct, my Apologies :slightly_smiling_face:, Clearly my string formatting knowledge is rusty.

Forgot you could do that, Good work @Blockzez