Comparing formatted numbers in StringValues

You can write your topic however you want, but you need to answer these questions:

  1. I am trying to compare formatted StringValue numbers, basically:
    1000 = 1.0K
    1600 = 1.6K
    16432 = 16.4K
    72864 = 72.9K

  2. What is the issue? Include screenshots / videos if possible!
    I cannot compare integers with StringValues, im trying to figure out a way to fix this by using a special function or a different value, I tried IntValue and NumberValue but those dont accept decimals as far as im concerned.
    image

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Looked through multiple other posts involving similar situations but couldnt find any in the exact same situation as I am in, I’m sure they are out there somewhere but I cant find them.

This is the comparing code that I was talking about

	if clicks.Value >= 1000 then
		clicks.Value = i18n:Format(clicks.Value)
		clicksCounter.Text = clicks.Value
	elseif gems.Value >= 1000 then
		gems.Value = i18n:Format(gems.Value)
		gemsCounter.Text = gems.Value
	elseif rebirths.Value >= 1000 then
		rebirths.Value = i18n:Format(rebirths.Value)
	end

I can provide the full code if anyone wants it, however I dont know how to do a dropdown/spoiler on devforum

Are the StringValues unformatted? For example, is it clicks.Value = "1000" or clicks.Value = 1.0K"?

If it’s the former, it’s as simple as:

if tonumber(clicks.Value) >= 1000 then

If it’s the latter, you may want to consider storing the string pre-format inside of the value, only formatting it in TextLabels when it is being displayed.

they are not formatted yet, after that is the update events for all of them where they get formatted if they are over 1000 again, but I just realized if I format it before the update it will also cause me to not be able to check it for the update event so I dont know

lemme rip this rite out my game for u

CurrencyDisplay.Text = Coins.Value
	if string.len(tostring(Coins.Value)) == 6 or string.len(tostring(Coins.Value)) == 9 then
		CurrencyDisplay.Text = tostring(Coins.Value):reverse():gsub("(%d%d%d)", "%1,"):reverse():sub(2)
	elseif string.len(tostring(Coins.Value)) > 3 then
		CurrencyDisplay.Text = tostring(Coins.Value):reverse():gsub("(%d%d%d)", "%1,"):reverse():sub(1)
	end

Thank you, I will try this soon

1 Like

Yeah thanks, I was using tonumber() wrong

1 Like