ProCoder
|
  |
| Joined: 17 Oct 2013 |
| Total Posts: 16 |
|
|
| 02 Feb 2015 03:31 PM |
Hello, a lot of games use big numbers in general e.g(1000000). This can be very annoying and hard to read. I have developed A free function that fixes this.
function comma_value(amount) local formatted = amount while true do formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2') if (k==0) then break end end return formatted end
The result: comma_value(1000) returns "1,000" |
|
|
| Report Abuse |
|
|
| |
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 02 Feb 2015 03:34 PM |
...
if i wanted comma-ed numbers i would have made my own function for it |
|
|
| Report Abuse |
|
|
|
| 02 Feb 2015 03:36 PM |
Can be smaller eg:
function comma_value(amount) local formatted = amount while k ~= 0 do formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2') end return formatted end |
|
|
| Report Abuse |
|
|
128GB
|
  |
| Joined: 17 Apr 2014 |
| Total Posts: 8056 |
|
|
| 02 Feb 2015 03:42 PM |
@Leg Why did you not make k local?
Also http://www.roblox.com/--item?id=53225998 |
|
|
| Report Abuse |
|
|
|
| 02 Feb 2015 03:51 PM |
I never read over it but I just noticed there was a unneeded if that was there but this is as short as it can be
function comma_value(amount) while k ~= 0 do amount, k = string.gsub(amount, "^(-?%d+)(%d%d%d)", '%1,%2') end return amount end
or
comma_value = function(amount)while k ~= 0 do amount, k = string.gsub(amount, "^(-?%d+)(%d%d%d)", '%1,%2') end return amount end
but being short does not really matter that much |
|
|
| Report Abuse |
|
|
|
| 02 Feb 2015 03:54 PM |
| hmmm that look awfully familiar to his orignal code... |
|
|
| Report Abuse |
|
|