Log in to vote

2
I have a problem, I tried to make a K,M,B system, but there is a problem, roblox changes big numbers to numbers like this one --> 1.298018197102000063e+42. But I convert it to a string, so my script sees the number like 1.2 --> wich will result in something like 1K.

This is very annoying, so my question is, is there any way to change them back in a script? (I tried searching for it but I don't know how it's called if there is a name for it).

**The script works fine when roblox didn't change the value**

(This is my script)

local module = {} local HighNumbers = { ['K'] = 1000, ['M'] = 1000000, ['B'] = 1000000000, ['T'] = 1000000000000, ['Qd'] = 1000000000000000, ['Qn'] = 1000000000000000000, ['Sx'] = 1000000000000000000000, ['Sp'] = 1000000000000000000000000, ['O'] = 10000000000000000000000000000, ['N'] = 10000000000000000000000000000000, ['D'] = 10000000000000000000000000000000000, ['Ud'] = 1000000000000000000000000000000000000, ['TdD'] = 100000000000000000000000000000000000000, ['QdD'] = 100000000000000000000000000000000000000000, ['QnD'] = 100000000000000000000000000000000000000000000, ['SxD'] = 100000000000000000000000000000000000000000000000, ['SpD'] = 100000000000000000000000000000000000000000000000000, ['SpD'] = 1000000000000000000000000000000000000000000000000000, ['OcD'] = 1000000000000000000000000000000000000000000000000000000, ['NvD'] = 1000000000000000000000000000000000000000000000000000000000, ['VgN'] = 1000000000000000000000000000000000000000000000000000000000000, ['UvG'] = 1000000000000000000000000000000000000000000000000000000000000000, ['DvG'] = 1000000000000000000000000000000000000000000000000000000000000000000, ['TvG'] = 1000000000000000000000000000000000000000000000000000000000000000000000, ['QtV'] = 1000000000000000000000000000000000000000000000000000000000000000000000000, ['QnV'] = 1000000000000000000000000000000000000000000000000000000000000000000000000000, ['SeV'] = 1000000000000000000000000000000000000000000000000000000000000000000000000000000, ['SpG'] = 1000000000000000000000000000000000000000000000000000000000000000000000000000000000, ['OvG'] = 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000, ['NvG'] = 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000, ['TgN'] = 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000, ['UtG'] = 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 } local HighestNum = 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 local HighestName = 'UtG' local HC = 999 local Pattern = '%d+' function module.Convert(Number) for i,v in pairs(HighNumbers) do local Rounded = tostring(Number/v):match(Pattern) --> It goes wrong here --warn('n '..Number..'v '..v..'r '..Rounded) local RoundedNum = tonumber(Rounded) warn(Number) if Number >= v and RoundedNum and RoundedNum < 1000 and Number >= 1000 and Number < HighestNum * HC then local Result = Rounded..i warn(Result) return Result elseif Number < 1000 then warn(Number) return Number elseif Number > HighestNum * HC then warn(Number/HighestNum..HighestName) return Number/HighestNum..HighestName end end end return module

EDIT: Thanks to MCAndRobloxUnited I found the solution:

*Cannot copy the solution, but go take a look at string.format, you can find it there*
--> Works great

IF ANYONE HAS TROUBLE WITH THIS, YOU CAN EITHER REPLY TO THIS OR SEND ME A MESSAGE TO ME (/MY ROBLOX PROFILE)

0

why go past KMBT tho. scientific notation is properly concise for big numbers. cabbler 1937 — 2y

0

It's because the game I'm working on purpose is to make as much money as possible, so, is there a way to make it a number again, even if it requeres more string manipulation? RedcommanderV2 1256 — 2y

Log in to vote

0
1.298018197102000063e+42 is actually 1.298018197102000063 * 10^42. Just for easier maths.

Hope this helps!

0

Like I said, it's already solved, I already firgured out it was the scientific notation and I used some string patterns to make it a normal notation again RedcommanderV2 1256 — 2y

0

That's great to hear! I just noticed that edit though... Good luck with your scripts! lazycoolboy500 537 — 2y

Log in to vote

0
I know that you said this question was solved, but I thought I would post an interesting solution I found for people who need to know this kind of thing and find your question. Here is how I overcame this problem:

money.Changed:Connect(function() local amountLableFound = false for i = 3, 12, 3 do if money.Value >= (10 ^ i) and money.Value < (10 ^ (i + 3)) then amountLableFound = true local uncheckedMVariable = (math.floor(money.Value / (10 ^ (i - 2))) / 100) local strMVariable = tostring(uncheckedMVariable) local decimalCheck = string.find(strMVariable, "%.") local mVariable if decimalCheck and decimalCheck ~= 4 then mVariable = string.sub(strMVariable, 1, 4) else mVariable = string.sub(strMVariable, 1, 3) end if money.Value > (uncheckedMVariable * (10 ^ (i - 2)) * 100) then if money.Value >= (10 ^ 12) then cash.Value = mVariable.."T+" elseif money.Value >= (10 ^ 9) then cash.Value = mVariable.."B+" elseif money.Value >= (10 ^ 6) then cash.Value = mVariable.."M+" elseif money.Value >= (10 ^ 3) then cash.Value = mVariable.."K+" end else if money.Value >= (10 ^ 12) then cash.Value = mVariable.."T" elseif money.Value >= (10 ^ 9) then cash.Value = mVariable.."B" elseif money.Value >= (10 ^ 6) then cash.Value = mVariable.."M" elseif money.Value >= (10 ^ 3) then cash.Value = mVariable.."K" end end end end if not amountLableFound then cash.Value = math.floor(money.Value) end end)

Note: cash is a string value and money is a number value. cash is what displays on the leaderboard. If you need larger amounts just add on to the length of the for loop and add on an elseif. I hope you find this helpful(to anyone who finds this). I also hope that you find this interesting @RedcommanderV2.