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 » Scripters
Home Search
 

Re: Getting the length of a number like #num ?

Previous Thread :: Next Thread 
Soybeen is not online. 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
Lord_Narwhal is not online. Lord_Narwhal
Joined: 05 May 2012
Total Posts: 3242
09 Aug 2016 03:49 PM
print(string.len(tostring(num)))


Formerly xXTheRobotXx, add 13,349 posts
Report Abuse
Tynezz is not online. Tynezz
Joined: 28 Apr 2014
Total Posts: 4945
09 Aug 2016 03:49 PM
local number=103044895

print(tostring(number):len())
Report Abuse
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
09 Aug 2016 03:49 PM
#tostring(num)
Report Abuse
thedailyblarg is not online. thedailyblarg
Joined: 26 Feb 2012
Total Posts: 5506
09 Aug 2016 03:50 PM
print(#tostring(number))
Report Abuse
Soybeen is not online. 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 is not online. 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 is not online. Tynezz
Joined: 28 Apr 2014
Total Posts: 4945
09 Aug 2016 03:52 PM
@Soy, pretty sure you can
Report Abuse
thedailyblarg is not online. thedailyblarg
Joined: 26 Feb 2012
Total Posts: 5506
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 is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
09 Aug 2016 03:53 PM
Why?
Report Abuse
Soybeen is not online. 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
Lord_Narwhal is not online. Lord_Narwhal
Joined: 05 May 2012
Total Posts: 3242
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 is not online. 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 is not online. 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 is not online. 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 is not online. 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
thedailyblarg is not online. thedailyblarg
Joined: 26 Feb 2012
Total Posts: 5506
09 Aug 2016 03:55 PM
^ LMAO you are a truly mentally ill person.

print(#tostring(1234)) == 4

print(#("yay")) == 3
Report Abuse
Lord_Narwhal is not online. Lord_Narwhal
Joined: 05 May 2012
Total Posts: 3242
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 is not online. 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
thedailyblarg is not online. thedailyblarg
Joined: 26 Feb 2012
Total Posts: 5506
09 Aug 2016 03:56 PM
^ Because you have a huge ego and fail to understand simple concepts like that :)
Report Abuse
Tynezz is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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