Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I remove decimal values from these numbers?

I'm making a Value that shows in a GUI. I'd like to know how to make the text say 1.34B when the player has 1345869475 "dollars", but it comes up as 1.345869475B. Can someone help me simplify this?

while wait() do
	Value = script.Parent.Parent.Parent.Parent.Parent.NPCNumber.Warrior.Value
	if Value < 1000000 then script.Parent.Text = Value
	else if Value >= 1000000 and Value < 1000000000 then script.Parent.Text = (Value/1000000).."M"
	else if Value >= 1000000000 and Value < 2147483647 then script.Parent.Text = (Value/1000000000).."B"
	else if Value == 2147483647 then script.Parent.Text = "MAX"
	end
	end
	end
	end
end

Any help is appreciated THANKS!

1 answer

✓ Accepted answer

you could do something like this: (math.floor(Value/10^7))/10^2 Basically, put the number in the billion's place value in the hundred's place value, then round down to the nearest whole number, and then move the digit in the hundred's place to the one's place. That will give you two numbers behind the decimal and the number of billions in front of the decimal.

Example:

Value = 12425415074
--Value/10^7 =  1242.5415074
--math.floor(Value/10^7) = 1242
--(math.floor(Value/10^7))/10^2 = 12.42
print((math.floor(Value/10^7))/10^2.." B") -----------> 12.42 B

4 comments

1

I'm new to the site, so it would help me if you could tell me how to put the code into context similar to the example you showed.

0

click the button above the text box that says Lua...and then type in between the ~~~~'s

0

And this worked! Thanks!

0

Alright, thanks. Glad to help.

This discussion is preserved as it was. New answers, comments, and votes are closed.