How to implement this "function to my code" - decimals abbreviation

  1. What do you want to achieve?
    So Im recently using abbreviation module but I need also decimals abbreviation for numbers like 9.199999901.
  2. What is the issue? Include screenshots / videos if possible!
    When I tried to implement it to my code, numbers on gui was froze
  3. What solutions have you tried so far?
    I took part of this code from devforum and Im still beginner so I tried to figured it out by myself but I wasnt able to do that so thats why Im here.

My code without decimal abbreviation:

local M = require(game.ReplicatedStorage:WaitForChild("ModuleScript"))
local plr = game.Players.LocalPlayer
local stats = plr.Stats.Cash.Value
while wait() do
	script.Parent.Text = " "..M.ZeroTwoIsCute(stats)
end

Decimal abbreviation script:

   local str = string.format("%.2f", stats)
  stats = tonumber(str)

Thank you for helping me with this basic problem as I said Im still beginner so thats it.

I think its because you overloaded with decimals, maybe its overloading number registers and causing crash. Can you record how it works and i have to ask, Decimal abbreviation script is
game.ReplicatedStorage:WaitForChild(“ModuleScript”)?

Yes normal abbreviation is game.ReplicatedStorage:WaitForChild(“ModuleScript”),
and I will try.

I believe you need to return a value in the module script.

return function()
    return tonumber(string.format(“.2f”,stats))
end

So you telling me that I need to implement return value in normal Abbreviation module?

1 Like

From what I see, correct. The string appears to be “froze” because it is probably not returning any values.

Alright so this is the script so I need to define stats?

local M = {}
local ZeroTwoCute = {"K","M","B","T"}

M.ZeroTwoIsCute = function(Input)
	for ZeroTwo = #ZeroTwoCute, 1, -1 do
		local v = math.pow(10, ZeroTwo * 3)
		if Input >= v then
			return tostring(Input / v):sub(1,5)..ZeroTwoCute[ZeroTwo]
		end
	end
	return tostring(Input)
end
return M

Okay so I solve it by “if statement” thank you all for help.

1 Like