generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Automatically adding commas to large numbers?

Previous Thread :: Next Thread 
Smirky is not online. Smirky
Joined: 05 Apr 2008
Total Posts: 3598
29 Dec 2011 05:51 PM
Hi guys,

I don't need this for any particular reason, but I want to know if there is a print function to add commas to the output when printing a number like 1000000 (as a number, not string)?

For example, printing 1000000 as 1,000,000?

Thanks.
Report Abuse
Xsitsu is not online. Xsitsu
Joined: 28 Jul 2009
Total Posts: 2921
29 Dec 2011 05:59 PM
I believe you would have to make your own.
Report Abuse
metaplates is not online. metaplates
Joined: 20 Dec 2011
Total Posts: 423
29 Dec 2011 06:16 PM
That will require a custom function. :)

I have it but it's not letting me post it.


-metaplates, Master of JavaScript.
Report Abuse
Merlin11188 is not online. Merlin11188
Joined: 20 Dec 2007
Total Posts: 4158
29 Dec 2011 06:26 PM
It's not letting me post mine. I'll PM it to you.
Report Abuse
Smirky is not online. Smirky
Joined: 05 Apr 2008
Total Posts: 3598
29 Dec 2011 06:31 PM
@Merlin,

If you were talking to me, I never got your PM.
Report Abuse
Merlin11188 is not online. Merlin11188
Joined: 20 Dec 2007
Total Posts: 4158
29 Dec 2011 06:33 PM
Oh dear. That's not good. It probably got auto-filtered like my post.
Report Abuse
Merlin11188 is not online. Merlin11188
Joined: 20 Dec 2007
Total Posts: 4158
29 Dec 2011 06:36 PM
function InsertCommas ( number )
number = tostring(number)
number = number:reverse()
number = number:gsub("%d%d%d", function(a) return a .. "," end)
number = number:reverse()
number = number:sub(number:find("%d"), -1)
return number
end

print(InsertCommas(1000000)) -- 1,000,000
Report Abuse
Merlin11188 is not online. Merlin11188
Joined: 20 Dec 2007
Total Posts: 4158
29 Dec 2011 06:37 PM
Phew. Got it through.

~Floodcheck~
Report Abuse
skipperguy12 is not online. skipperguy12
Joined: 09 Oct 2009
Total Posts: 955
29 Dec 2011 06:42 PM
Crazyman32 made one too :P
Report Abuse
Smirky is not online. Smirky
Joined: 05 Apr 2008
Total Posts: 3598
29 Dec 2011 06:48 PM
Woah! Is that the simplest way to do it?
Report Abuse
crazyman32 is not online. crazyman32
Joined: 13 Apr 2008
Total Posts: 18027
29 Dec 2011 08:39 PM
This is the one from my model:

function addComma(n)
local f,k = n
while (true) do
f,k = string.gsub(f,"^(-?%d+)(%d%d%d)","%1,%2")
if (k == 0) then break end
end
return f
end

-- Example:
print(addComma(100000.25))



No, I'm not a string manipulator genius. I found that part on google :P
Report Abuse
DXPower is not online. DXPower
Joined: 21 Oct 2008
Total Posts: 2866
29 Dec 2011 09:03 PM
O_e

Free Fireworks!
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image