i_mi
|
  |
| Joined: 27 Sep 2015 |
| Total Posts: 61 |
|
|
| 28 Jul 2016 12:34 PM |
So I made a number abbreviation script, like this, but it's literally 75 lines, and if I were to add more, it would lengthen it a lot longer. Also I have to find out how many zero's and it hurts my brain. Can you help shorten it dramatically by putting a string function or something and a table where the function iterates from that correlates to the type at the end? Also in the last suffix can you tag a "+" at the end without decimals? Thanks, here's the code.
https://www.roblox.com/item.aspx?id=466871497
|
|
|
| Report Abuse |
|
|
|
| 28 Jul 2016 12:36 PM |
| You mean like 1000000 -> 1M and 1000001 -> 1M+? |
|
|
| Report Abuse |
|
|
i_mi
|
  |
| Joined: 27 Sep 2015 |
| Total Posts: 61 |
|
|
| 28 Jul 2016 12:40 PM |
No
I was thinking of like
local suf = {k, M, B, T, qd}
Only qd has the "qd+" for example 5qd+
but numbers like 9999999
become 9.99M
|
|
|
| Report Abuse |
|
|
Kodran
|
  |
| Joined: 15 Aug 2013 |
| Total Posts: 5330 |
|
|
| 28 Jul 2016 12:55 PM |
roblox filter is at it again.
here: http://pastebin.com/raw/44w14cuz |
|
|
| Report Abuse |
|
|
i_mi
|
  |
| Joined: 27 Sep 2015 |
| Total Posts: 61 |
|
|
| 28 Jul 2016 12:59 PM |
I want to tag along some decimals, 1111111 becomes 1.11M, like that. Yours does not tag along some decimals.
|
|
|
| Report Abuse |
|
|
i_mi
|
  |
| Joined: 27 Sep 2015 |
| Total Posts: 61 |
|
|
| 28 Jul 2016 01:00 PM |
Just the first two are fine
|
|
|
| Report Abuse |
|
|
Kodran
|
  |
| Joined: 15 Aug 2013 |
| Total Posts: 5330 |
|
|
| 28 Jul 2016 01:02 PM |
Simple rounding can do that,
replace: return math.floor(n/(v[2])+0.5)..v[1]
with: return math.floor(n/10+0.5)*10/v[2]..v[1] |
|
|
| Report Abuse |
|
|
Taryo
|
  |
| Joined: 06 Aug 2011 |
| Total Posts: 496 |
|
|
| 28 Jul 2016 02:04 PM |
local titles = {"k","m","b","t","qd","qn","sx"}
local function addtitle(number) if number < 1000 then return tostring(number) end local length = math.floor(math.log10(number)+1); local of3 = length%3; local extend = (length-of3)/3; local divide = 10^(extend*3) print(divide) local String = "" if length <= #titles*3 then if of3 ==0 and extend-1 <= #titles then divide = divide/10 extend = extend-1 end String = tostring(number/divide)..titles[extend] else String = "999"..titles[#titles].."+" end return String end |
|
|
| Report Abuse |
|
|
Taryo
|
  |
| Joined: 06 Aug 2011 |
| Total Posts: 496 |
|
|
| 28 Jul 2016 02:06 PM |
-- Oops, didn't read the part where you wanted a + suffix... Here's the fix:
local titles = {"k","m","b","t","qd","qn","sx"}
local function addtitle(number) if number < 1000 then return tostring(number) end local length = math.floor(math.log10(number)+1); local of3 = length%3; local extend = (length-of3)/3; local divide = 10^(extend*3) print(divide) local String = "" if length <= #titles*3 then if of3 ==0 and extend-1 <= #titles then divide = divide/10 extend = extend-1 end String = tostring(number/divide)..titles[extend].."+" else String = "999"..titles[#titles].."+" end return String end |
|
|
| Report Abuse |
|
|
Kodran
|
  |
| Joined: 15 Aug 2013 |
| Total Posts: 5330 |
|
|
| 28 Jul 2016 02:06 PM |
but mines so much.. shorter...
function shorten(n) for i,v in next,stuff do if n>=v[2] and (n<((stuff[i+1] and stuff[i+1][2]) or math.huge)) then return math.floor(n/10+0.5)*10/v[2]..v[1] end end return n end |
|
|
| Report Abuse |
|
|
Taryo
|
  |
| Joined: 06 Aug 2011 |
| Total Posts: 496 |
|
| |
|
Kodran
|
  |
| Joined: 15 Aug 2013 |
| Total Posts: 5330 |
|
|
| 28 Jul 2016 02:22 PM |
| It was in the pastebin, he got what he wanted |
|
|
| Report Abuse |
|
|
Taryo
|
  |
| Joined: 06 Aug 2011 |
| Total Posts: 496 |
|
|
| 28 Jul 2016 02:59 PM |
local titles = {"k","m","b","t","qd","qn","sx"}
local function addtitle(number) local l,s = math.floor(math.log10(number)+1),tostring(number) for k,t in ipairs(titles) do if l>k*3 and l<=(k+1)*3 then if l%3~=0 then return s:sub(1,l%3).."."..s:sub(l%3+1,l%3+1)..t.."+" else return s:sub(1,3).."."..s:sub(4,4)..t.."+" end;end;end return s end
-- Doesn't require tables to be in the titles! Hahaha! |
|
|
| Report Abuse |
|
|
i_mi
|
  |
| Joined: 27 Sep 2015 |
| Total Posts: 61 |
|
|
| 28 Jul 2016 04:06 PM |
Hey, that's weird. I did print(addtitle(112512123112351)) and there were two decimal places. Yeah I just typed some quick random numbers to try to see if it works, but I got 1.1.2T.
|
|
|
| Report Abuse |
|
|
i_mi
|
  |
| Joined: 27 Sep 2015 |
| Total Posts: 61 |
|
|
| 28 Jul 2016 04:07 PM |
And what I mean was at the last index of the table, I only wanted THAT to have the "+" sign.
|
|
|
| Report Abuse |
|
|
Kodran
|
  |
| Joined: 15 Aug 2013 |
| Total Posts: 5330 |
|
|
| 28 Jul 2016 04:10 PM |
^^ mine won't do that :)
And I'm still confused about the plus signs. Give examples of number that would and wouldn't have them. |
|
|
| Report Abuse |
|
|
|
| 28 Jul 2016 04:11 PM |
@kodran >100 decillion?
blobfish are going to be bricks for my wall; tardigrades are going to be the glue for my wall |
|
|
| Report Abuse |
|
|
i_mi
|
  |
| Joined: 27 Sep 2015 |
| Total Posts: 61 |
|
|
| 28 Jul 2016 04:12 PM |
Turned out ROBLOX added an e+# to the end. I can live with it, however.
|
|
|
| Report Abuse |
|
|
Kodran
|
  |
| Joined: 15 Aug 2013 |
| Total Posts: 5330 |
|
|
| 28 Jul 2016 04:14 PM |
| What greater than 100 decillion? |
|
|
| Report Abuse |
|
|
i_mi
|
  |
| Joined: 27 Sep 2015 |
| Total Posts: 61 |
|
|
| 28 Jul 2016 04:25 PM |
Undec, Duodec, Tridec, etc.
And 100T and above is glitching with two decimal points, along with number placement
|
|
|
| Report Abuse |
|
|
|
| 28 Jul 2016 04:25 PM |
i mean if the number is greater than 100 decillion, it just puts a plus?
blobfish are going to be bricks for my wall; tardigrades are going to be the glue for my wall |
|
|
| Report Abuse |
|
|
i_mi
|
  |
| Joined: 27 Sep 2015 |
| Total Posts: 61 |
|
|
| 28 Jul 2016 04:27 PM |
No, the highest index in the table
for example,
local t = {k, M, B, T, qd, Qn}
The highest index in the table is Qn
so it will be like 82Qn+
whilst others, like 82.55T
|
|
|
| Report Abuse |
|
|
|
| 28 Jul 2016 04:29 PM |
oh, i was thinking if you didnt want to put everything in the same table (local t = {k, M, B, T, qd, Qn, sx, sp, oc})
just put a plus after the last one
blobfish are going to be bricks for my wall; tardigrades are going to be the glue for my wall |
|
|
| Report Abuse |
|
|
Taryo
|
  |
| Joined: 06 Aug 2011 |
| Total Posts: 496 |
|
|
| 29 Jul 2016 12:56 AM |
| Yes, there seems to be an issue... I'll fix it. |
|
|
| Report Abuse |
|
|