Kie413
|
  |
| Joined: 13 Oct 2013 |
| Total Posts: 230 |
|
|
| 29 Oct 2013 12:05 PM |
I need it so when a player has more than or equal to 1000 it puts a , in between like this 1,000
Examples: 1,000 10,000 100,000 1,000,000 10,000,000 100,000,000 1,000,000,000
Here is the script:
while wait() do script.Parent.Text = "" .. math.floor(game.Players.LocalPlayer.leaderstats.CRE.Value) end |
|
|
| Report Abuse |
|
|
Kie413
|
  |
| Joined: 13 Oct 2013 |
| Total Posts: 230 |
|
| |
|
Kie413
|
  |
| Joined: 13 Oct 2013 |
| Total Posts: 230 |
|
|
| 29 Oct 2013 12:54 PM |
| It's hard to see what amount you have. |
|
|
| Report Abuse |
|
|
Kie413
|
  |
| Joined: 13 Oct 2013 |
| Total Posts: 230 |
|
| |
|
MHebes
|
  |
| Joined: 04 Jan 2013 |
| Total Posts: 2278 |
|
|
| 29 Oct 2013 01:14 PM |
| I actually made this exact script a while back. When I get home I'll post it here. The basic premise was to make the string backwards and insert a comma every 3rd letter. |
|
|
| Report Abuse |
|
|
Kie413
|
  |
| Joined: 13 Oct 2013 |
| Total Posts: 230 |
|
| |
|
|
| 29 Oct 2013 01:32 PM |
@Mh What if the number was 1000.1234 @Op Unless you've got a custom leaderboard I don't think you can add (",") text to the scoreboard Could be wrong, I never use the leaderboard |
|
|
| Report Abuse |
|
|
OldGoldie
|
  |
| Joined: 17 Aug 2010 |
| Total Posts: 8210 |
|
|
| 29 Oct 2013 01:39 PM |
| There's a function for it, but I don't know what it is. |
|
|
| Report Abuse |
|
|
janthran
|
  |
| Joined: 15 May 2009 |
| Total Posts: 17429 |
|
|
| 29 Oct 2013 01:56 PM |
back=string.reverse(tostring(#)) new=string.sub(back,0,3) withcomma=new..","
just add a generic for loop and |
|
|
| Report Abuse |
|
|
Kie413
|
  |
| Joined: 13 Oct 2013 |
| Total Posts: 230 |
|
|
| 29 Oct 2013 02:04 PM |
I have a script that shows the leaderstat CRE as text in the GUI.
|
|
|
| Report Abuse |
|
|
|
| 29 Oct 2013 02:08 PM |
s = "25263532" s = s:reverse() repeat s, l = string.gsub(s, "(%d%d%d)(%d)", "%1,%2",1) until l == 0 print(s:reverse())
--Horrible. But working. |
|
|
| Report Abuse |
|
|
MHebes
|
  |
| Joined: 04 Jan 2013 |
| Total Posts: 2278 |
|
|
| 29 Oct 2013 02:11 PM |
@janthan It's a tad more complicated than you make it out to be. @OP Here you go - couldn't find the old one, so I made a new one. If you have really high numbers (like 17 0's), it starts going weird with scientific notation, and I had to round to the nearest 100th place for decimals.
USAGE: GetFormatted( Float `number` ) `number` : Any number really returns : String : `number` with commas added in and rounded to the nearest 100th. example : print(GetFormatted(142581184.1841)) > 142,581,184.18
local function GetFormatted(number) if number < 1000 then return tostring(number) end local int,dec = math.modf(number) int = tostring(int):reverse() dec = dec~=0 and tostring(math.floor(dec*100+0.5)/100):sub(3) or nil local sections = {} for i = 1,#int,3 do table.insert(sections,1,int:sub(i,i+2):reverse()) end int = table.concat(sections,",") return int .. (dec and "." .. dec or "") end |
|
|
| Report Abuse |
|
|
MHebes
|
  |
| Joined: 04 Jan 2013 |
| Total Posts: 2278 |
|
|
| 29 Oct 2013 02:13 PM |
| Ninja'd me. Also, looks like I'm terrible with string patterns lol. |
|
|
| Report Abuse |
|
|
|
| 29 Oct 2013 02:14 PM |
| Mine will attempt to put commas in decimals... I need to fix that. |
|
|
| Report Abuse |
|
|
|
| 29 Oct 2013 02:16 PM |
dp = 3 --Decimal Places n = 25263532.3152 --That number i, d = math.modf(n, 2) s = tostring(i):reverse() repeat s, l = string.gsub(s, "(%d%d%d)(%d)", "%1,%2",1) until l == 0 print(s:reverse() .. tostring(d):sub(2, 2+dp)) |
|
|
| Report Abuse |
|
|
MHebes
|
  |
| Joined: 04 Jan 2013 |
| Total Posts: 2278 |
|
|
| 29 Oct 2013 02:22 PM |
| Also, TIL that modf sucks at getting the decimal part of a number. |
|
|
| Report Abuse |
|
|
|
| 29 Oct 2013 02:23 PM |
| Are you talking about it having 0.3152 showing as 0.31520000100136? |
|
|
| Report Abuse |
|
|
MHebes
|
  |
| Joined: 04 Jan 2013 |
| Total Posts: 2278 |
|
|
| 29 Oct 2013 02:35 PM |
| Yeah. I know it has to do with floating point inaccuracies, but I don't see why they didn't just have it literally chop off the decimal displayed. |
|
|
| Report Abuse |
|
|
|
| 29 Oct 2013 02:37 PM |
That's a problem of print, not modf.
Argh, stupid floodcheck. |
|
|
| Report Abuse |
|
|
MHebes
|
  |
| Joined: 04 Jan 2013 |
| Total Posts: 2278 |
|
|
| 29 Oct 2013 02:42 PM |
local n = 10000.313244 local int,dec = math.modf(n) print(n, int.."."..dec) > 10000.313244 10000.0.31324400000085
Could still be print, but it's something about modf that screws with the number. |
|
|
| Report Abuse |
|
|
|
| 29 Oct 2013 02:44 PM |
| They are the same number (Well, you forgot that its not '3132...' but '0.3132...'), only the '0.3132...' one shows more DP. |
|
|
| Report Abuse |
|
|
|
| 29 Oct 2013 02:45 PM |
@MHebes:
local n = 23325.3254532 local i, d = math.modf(n) print(i + d == n) |
|
|
| Report Abuse |
|
|
MHebes
|
  |
| Joined: 04 Jan 2013 |
| Total Posts: 2278 |
|
| |
|