|
| 12 Jan 2016 08:57 AM |
converting a number (like 1537) to 1.5k I can think of a way to do this but it would be highly inefficient and a waste of time, all I need to see is how it would be done in the thousands thanks |
|
|
| Report Abuse |
|
|
|
| 12 Jan 2016 08:58 AM |
| (I'm going to manipulate numbers other than a thousand so don't just make it divide the number by 1k) |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 12 Jan 2016 09:37 AM |
[Post blocked] http://codepad.org/H27p1Bl3
I hope I don't get banned for trying to post code.
|
|
|
| Report Abuse |
|
|
|
| 12 Jan 2016 10:25 AM |
Thanks a lot, do you mind messaging me how this works?
|
|
|
| Report Abuse |
|
|
|
| 12 Jan 2016 02:05 PM |
bump (script that was given rounds the number up instead of giving real value)
|
|
|
| Report Abuse |
|
|
|
| 12 Jan 2016 02:46 PM |
does anyone know how to do this?
|
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 12 Jan 2016 02:49 PM |
| Still lost, what are you exactly trying to do? Just change a number like 4567 to 4.567k or what? |
|
|
| Report Abuse |
|
|
|
| 12 Jan 2016 02:54 PM |
similar to how other tycoons do it, I want to know how you can compress any number down to only 3 digits; 4,567 = 4.56k 9,223,372 = 9.22m 107,888,103 = 107m and so on...do you know how that's possible?
|
|
|
| Report Abuse |
|
|
|
| 12 Jan 2016 02:55 PM |
and while obviously leaving numbers < 1,000 unmanipulated
|
|
|
| Report Abuse |
|
|
|
| 12 Jan 2016 02:55 PM |
It's simple string manipulation. Here's an example:
string.format("%.1fK", n / 1000.0) where 'n' would be your number.
http://www.lua.org/pil/20.html |
|
|
| Report Abuse |
|
|
|
| 12 Jan 2016 02:56 PM |
^ not what I'm asking. thx anyway though
|
|
|
| Report Abuse |
|
|
62GB
|
  |
| Joined: 03 Oct 2011 |
| Total Posts: 4157 |
|
|
| 12 Jan 2016 02:58 PM |
This is kinda inefficient but meh.
local NUMBER = 1300
local Mess = tostring(NUMBER)
print(Mess:sub(1,1).."."..Mess:sub(2,3).."k") |
|
|
| Report Abuse |
|
|
|
| 12 Jan 2016 02:59 PM |
^ again, not what I'm asking for :/
|
|
|
| Report Abuse |
|
|
62GB
|
  |
| Joined: 03 Oct 2011 |
| Total Posts: 4157 |
|
|
| 12 Jan 2016 03:00 PM |
'similar to how other tycoons do it, I want to know how you can compress any number down to only 3 digits; 4,567 = 4.56k 9,223,372 = 9.22m 107,888,103 = 107m and so on...do you know how that's possible?' |
|
|
| Report Abuse |
|
|
|
| 12 Jan 2016 03:01 PM |
lol why did you quote me? if you read through that you would know that yours only supports numbers under 1m
|
|
|
| Report Abuse |
|
|
| |
|
62GB
|
  |
| Joined: 03 Oct 2011 |
| Total Posts: 4157 |
|
|
| 12 Jan 2016 03:05 PM |
Then do something like.. I'm sure there's a better way but it's alright.
local cash = 1000
if cash >= 10000000 then --1b
elseif cash >= 1000000 then --1m
elseif cash >= 100000 then
elseif cash >= 10000 then
end |
|
|
| Report Abuse |
|
|
|
| 12 Jan 2016 03:06 PM |
yeah that's what I was thinking of when I put "inefficient and waste of time" in the OP that'll be my last resort lol
|
|
|
| Report Abuse |
|
|
| |
|
BanTech
|
  |
| Joined: 31 Dec 2015 |
| Total Posts: 886 |
|
|
| 12 Jan 2016 03:36 PM |
Replace num with your input. This is just a rough version but is something like this what you are after? Always 3 significant figures and adds the letter automatically?
num = 1356807340 mag = 0 compressed = num
while string.len(tostring(compressed)) > 3 do compressed = math.floor(compressed / 1000) mag = mag + 1 end
output = tostring(compressed) if string.len(output) < 3 then output = string.sub(tostring(num / 1000 ^ mag), 1, 4) end
letters = { "K+", "M+", "B+", "Q+", "Qn+" } if mag > 0 then output = output .. letters[mag] end |
|
|
| Report Abuse |
|
|
BanTech
|
  |
| Joined: 31 Dec 2015 |
| Total Posts: 886 |
|
|
| 12 Jan 2016 03:37 PM |
| Paste into a script in studio and put print(output) at the end to see the result |
|
|
| Report Abuse |
|
|
|
| 12 Jan 2016 03:38 PM |
3 Sig Figs*
#code 'The Legend of Heroes Sen no Kiseki' |
|
|
| Report Abuse |
|
|
|
| 12 Jan 2016 03:39 PM |
dude, that's perfect. thank you so much :^)
|
|
|
| Report Abuse |
|
|
BanTech
|
  |
| Joined: 31 Dec 2015 |
| Total Posts: 886 |
|
|
| 12 Jan 2016 03:40 PM |
| You're welcome, I'd neaten it up if I had more time but I'm sure you can edit it for your needs :) |
|
|
| Report Abuse |
|
|
koen523
|
  |
| Joined: 23 Feb 2011 |
| Total Posts: 4026 |
|
|
| 12 Jan 2016 03:45 PM |
| NecroBumpism you're clever ^^ |
|
|
| Report Abuse |
|
|