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
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Finding the number of digits.

Previous Thread :: Next Thread 
tastefulbobo is not online. tastefulbobo
Joined: 14 May 2010
Total Posts: 166
23 May 2013 07:18 PM
does ROBLOX have a method that allows you to find the number of digits that are in a number?
Report Abuse
CodyTheBuildingKid is not online. CodyTheBuildingKid
Joined: 13 Dec 2011
Total Posts: 4399
23 May 2013 07:25 PM
Number = 4.32
Numbers = 0

local String = tostring(Number)
for i = 1, String:len() do
if tonumber(String:sub(i, i)) then
Numbers = Numbers + 1
end
end
print(Numbers)
Report Abuse
MrNicNac is not online. MrNicNac
Joined: 29 Aug 2008
Total Posts: 26567
23 May 2013 07:27 PM
local number = math.pi
local digits = (function() local t = 0 for digit in tostring(number):gmatch("%d") do t = t + 1 end return t end)()

print(digits)

Should print around 13 or 14.
Report Abuse
tastefulbobo is not online. tastefulbobo
Joined: 14 May 2010
Total Posts: 166
23 May 2013 07:53 PM
wow... that is some FANCY scripting...
Report Abuse
1GREENBOB123456 is not online. 1GREENBOB123456
Joined: 07 Nov 2010
Total Posts: 56
23 May 2013 08:21 PM
It's not, all you need to do is:
Number = 123456789
Digits = string.len(tostring(Number))
Report Abuse
1Topcop is not online. 1Topcop
Joined: 09 Jun 2009
Total Posts: 6635
23 May 2013 08:34 PM
^ Won't account for decimal points.
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
23 May 2013 08:37 PM
num = 123456.789
numStr = tostring(num)
digits = numStr:match("%d+%.?"):len() + numStr:match("%.?%d*"):len() - 1

Report Abuse
MrNicNac is not online. MrNicNac
Joined: 29 Aug 2008
Total Posts: 26567
23 May 2013 08:39 PM
Oh there's actually an even simpler way...

local number = 123.23213
local digits = (tostring(number):gsub(".", "")):len()
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
23 May 2013 08:40 PM
Leave it to the flamingo to overthink it.
>_>

MNN wins again.
Report Abuse
1Topcop is not online. 1Topcop
Joined: 09 Jun 2009
Total Posts: 6635
23 May 2013 08:42 PM
function digits(num)return(tostring(tonumber(num) or ""):gsub(".",""):len()end

print(digits(3676))
print(digits("36.623"))
print(digits("hi"))

> 4
> 5
> 0

:3
Report Abuse
tastefulbobo is not online. tastefulbobo
Joined: 14 May 2010
Total Posts: 166
24 May 2013 03:21 PM
it doesnt need any decimals so thanks!
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