Hi everyone when i buy car original cost it 33k but when i try sold it. then showed like this i want to remove decimals how do i fix this? if anyone have solution please tell me thanks [ Im not good at explaining sorry ]
local function comma_value(amount)
local formatted = amount
while true do
formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
if (k==0) then
break
end
end
return formatted
end
script.Parent.Text = "¥"..tostring(comma_value(script.Parent.Parent.Parent.Parent.Parent.Parent:WaitForChild("Money").Value))
script.Parent.Parent.Parent.Parent.Parent.Parent:WaitForChild("Money").Changed:Connect(function()
script.Parent.Text = "¥"..tostring(comma_value(script.Parent.Parent.Parent.Parent.Parent.Parent:WaitForChild("Money").Value))
end)```
Try using math.round() there is now a way to remove decimal after comma in a number.
What does math.round do:
Returns the integer with the smallest difference between it and the given number. For example, the value 5.8 returns 6.
For values like 0.5 that are equidistant to two integers, the value with the greater difference between it and zero is chosen. In other words, the function rounds away from zero : 0.5 rounds to 1; -0.5 rounds to -1.|
This does work, however @OP wants to get rid of the decimals and nothing more, while this can occasionally give you a bonus number if you round up. Therefore I think it would be better to use math.floor for this case. This function always rounds down, which gives you a number without decimals while not adding any extra numbers due to rounding down.