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.
6087a044557d6b59ab52e7dd20f94da8?d=identicon&s=25 Peña, Botp (Guest)
on 2006-05-29 12: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
Bd0203dc8478deb969d72f52e741bd4f?d=identicon&s=25 Daniel Baird (Guest)
on 2006-05-29 12:34
(Received via mailing list)
On 5/29/06, Peña, Botp <botp@delmonte-phil.com> 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.