Forum: Ruby Re: Equivalent of Python zfill?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Peña, Botp (Guest)
on 2006-05-29 14:25
(Received via mailing list)
fr Peter:
# But if "0"*7 is the 'normal' way of doing this, it's OK with me.

in ruby in general, the shorter and simpler, the faster.

kind regards -botp
Daniel B. (Guest)
on 2006-05-29 14:34
(Received via mailing list)
On 5/29/06, Peña, Botp <removed_email_address@domain.invalid> wrote:
>
> fr Peter:
> # But if "0"*7 is the 'normal' way of doing this, it's OK with me.
>
> in ruby in general, the shorter and simpler, the faster.
>
> kind regards -botp
>
>

it might be worth profiling something like this:

# at start of code
lotsazeros = '0' * 1000

# various places in code
seven_zeros = lotsazeros[0..6]
three_thousand_and_ten_zeros = lotsazeros * 3 + '0' * 10

no idea how this performs, just thought it'd be worth trying..

;D
This topic is locked and can not be replied to.