Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 09 Aug 2016 03:49 PM |
For some reason I've never needed to do this. How can I get the length of a number?
|
|
|
| Report Abuse |
|
|
|
| 09 Aug 2016 03:49 PM |
print(string.len(tostring(num)))
Formerly xXTheRobotXx, add 13,349 posts |
|
|
| Report Abuse |
|
|
Tynezz
|
  |
| Joined: 28 Apr 2014 |
| Total Posts: 4945 |
|
|
| 09 Aug 2016 03:49 PM |
local number=103044895
print(tostring(number):len()) |
|
|
| Report Abuse |
|
|
| |
|
| |
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 09 Aug 2016 03:51 PM |
@Flux I need to do arithmetic on the result of #tostring(num)
|
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 09 Aug 2016 03:52 PM |
Can I just do tonumber(#tostring(num)) That seems odd
|
|
|
| Report Abuse |
|
|
Tynezz
|
  |
| Joined: 28 Apr 2014 |
| Total Posts: 4945 |
|
| |
|
|
| 09 Aug 2016 03:53 PM |
#tostring(num) is the length of it
you dont need tonumber lmao
# returns the length of any table or array (not dictionaries), or any string |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
| |
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 09 Aug 2016 03:54 PM |
Yep tonumber(#tostring(num)) works.
I would really like an easier way.
|
|
|
| Report Abuse |
|
|
|
| 09 Aug 2016 03:54 PM |
local length = 0 local num 1134 for i = 1,100 do repeat wait() length = length + 1 until 10^i+1 > num length = i
Formerly xXTheRobotXx, add 13,349 posts |
|
|
| Report Abuse |
|
|
Kodran
|
  |
| Joined: 15 Aug 2013 |
| Total Posts: 5330 |
|
|
| 09 Aug 2016 03:54 PM |
| you don't need tonumber, it's a number lmao. |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 09 Aug 2016 03:54 PM |
@Daily, again your idiocy precedes you.
I said I need to do math on the result. I cannot do math on a string.
Problem is solved with a mix of tonumber and tostring
|
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 09 Aug 2016 03:55 PM |
Uh...
#tostring(num)
math.floor(math.log(num, 10)+1) will also work for positive numbers. |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 09 Aug 2016 03:55 PM |
| Soybean, your idiocy precedes you. The length is a number. |
|
|
| Report Abuse |
|
|
|
| 09 Aug 2016 03:55 PM |
^ LMAO you are a truly mentally ill person.
print(#tostring(1234)) == 4
print(#("yay")) == 3 |
|
|
| Report Abuse |
|
|
|
| 09 Aug 2016 03:55 PM |
@eLunate
my exponential thinking was the same but yours is way more efficient
Formerly xXTheRobotXx, add 13,349 posts |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 09 Aug 2016 03:56 PM |
Hang on hang on hang on hang on Woooahh sorry everyone my brain is backfiring.
@eLunate I've had a dispute with daily in the past so I'm just predisposed to hating him.
Thank you everyone
|
|
|
| Report Abuse |
|
|
|
| 09 Aug 2016 03:56 PM |
| ^ Because you have a huge ego and fail to understand simple concepts like that :) |
|
|
| Report Abuse |
|
|
Tynezz
|
  |
| Joined: 28 Apr 2014 |
| Total Posts: 4945 |
|
|
| 09 Aug 2016 03:58 PM |
| I'm pretty sure I read somewhere on the wiki saying what eLunate is doing isn't recommended |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 09 Aug 2016 03:59 PM |
| Which one? I certainly wouldn't recommend either of them. |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 09 Aug 2016 03:59 PM |
Yes I have an ego, so does every other functioning human. @Ty The second method she posted?
|
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 09 Aug 2016 04:00 PM |
@Elunate then what would you suggest instead of either?
|
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 09 Aug 2016 04:01 PM |
| I suggest thinking about why you need the length of that number and what you plan on doing with it |
|
|
| Report Abuse |
|
|