Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I remove decimal values from these numbers?

Asked by 9 years ago

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

Log in to vote
0
Answered by 9 years ago

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
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. aquathorn321 858 — 9y
0
click the button above the text box that says Lua...and then type in between the ~~~~'s BSIncorporated 640 — 9y
0
And this worked! Thanks! BSIncorporated 640 — 9y
0
Alright, thanks. Glad to help. aquathorn321 858 — 9y
Ad

Answer this question