How to convert a StringValue with 1.1K+ (money) into a NumberValue; 1153

  1. What is the issue?

I use Zednov’s Tycoon Kit, but it’s changed a bit. There is a ‘StringValue’ named ‘Cash’ with however much cash the player has in leaderstats. But the problem is, it is a StringValue to make it K+, M+, B+, etc (thousands, millions, billions). How do I check if 1.1K+ is, for example, 1153 in Cash? I want to know how to change the K+, M+, B+, etc to the actual NumberValue instead of it being a string.

Sorry if the above wasn’t clear, if you have any questions I’ll answer them.

1 Like

You can use tonumber(string) to convert a string into a number though if youre talking about converting between the classes, then i dont know

That will not work. It results in an error. Because converting “K+” into a number is not allowed.

Just uncovert it! like how you converted it soo

local abbreviations = {
K = 10^3,
M = 10^6,
B = 10^9
}
local str = "1.1K"
local num
for i,v in pairs(abbreviations) do
if str:sub(#str,#str) == i then
num = tonumber(str:gsub(i,"")) * v
break
end
end

print(num) -- 1100 ?

I wrote it in devforum so it may not be that good but go check it.

local abbreviations = {
	K = 10^3,
	M = 10^6,
	B = 10^9
}
local str = "1.1K"
local num
for i,v in pairs(abbreviations) do
	if str:sub(#str,#str) == i then
		local n,t = str:gsub(i,"")
		num = tonumber(n)*v
		break
	end
end

print(num) -- 1100 ?

better script

1 Like

Error: “Attempt to get length of an Instance Value”

			if str:sub(#str,#str) == i then

I think it errors because the variable abbreviations is wrong. The cash is K+ it has a + on it. I do not know how to change that as it will not allow it in the variables because it thinks I am adding something…

image

in the script remove the ending + by doing
string.sub(StringValue.Value, 1, -2)

This probably works but someone else has helped me, thank you though!

Props to a guy called blackberrypi who went out of his way! :slight_smile:

1 Like
local abbreviations = {
	K = 10^3,
	M = 10^6,
	B = 10^9
}
local str = "1.1K"
local num
for i,v in pairs(abbreviations) do
	if str:sub(#str.Value,#str.Value) == i then
		local n,t = str.Value:gsub(i,"")
		num = tonumber(n)*v
		break
	end
end

print(num) -- 1100 ?