Forum: Ruby change from int 1 on int 01

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.
misiek (Guest)
on 2006-02-02 01:47
(Received via mailing list)
I need to change variable as int = 1 on  = 01

wrrrrwrrrrrrrrr
Malte M. (Guest)
on 2006-02-02 01:50
(Received via mailing list)
misiek wrote:
> I need to change variable as int = 1 on  = 01

May you elaborate?

Malte
Matthew S. (Guest)
on 2006-02-02 02:45
(Received via mailing list)
On Feb 1, 2006, at 21:58, Malte M. wrote:

> misiek wrote:
>> I need to change variable as int = 1 on  = 01
>
> May you elaborate?

Maybe he wants octal?
Ross B. (Guest)
on 2006-02-02 03:16
(Received via mailing list)
On Thu, 2006-02-02 at 06:57 +0900, misiek wrote:
> I need to change variable as int = 1 on  = 01

Based on the question, this is as likely as not what you're after:

1.to_s.rjust(2,'0')
# => "01"

sprintf('%.2d', 1)
# => "01"

That's strings, though. My math isn't great but I think int 1 *is* int
01 (isn't it?)

1.to_s.rjust(2,'0').to_i
# => 1
This topic is locked and can not be replied to.