|
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 23 May 2013 07:53 PM |
| wow... that is some FANCY scripting... |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| Joined: 09 Jun 2009 |
| Total Posts: 6635 |
|
|
| 23 May 2013 08:34 PM |
| ^ Won't account for decimal points. |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 23 May 2013 08:40 PM |
Leave it to the flamingo to overthink it. >_>
MNN wins again. |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 24 May 2013 03:21 PM |
| it doesnt need any decimals so thanks! |
|
|
| Report Abuse |
|
|