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.
9aa1e92a0ebb17fdaad2fa39b4c52b8a?d=identicon&s=25 misiek (Guest)
on 2006-02-02 00:47
(Received via mailing list)
I need to change variable as int = 1 on  = 01

wrrrrwrrrrrrrrr
386f25c3bb2696a57b79e55a649769fb?d=identicon&s=25 Malte Milatz (Guest)
on 2006-02-02 00:50
(Received via mailing list)
misiek wrote:
> I need to change variable as int = 1 on  = 01

May you elaborate?

Malte
31af45939fec7e3c4ed8a798c0bd9b1a?d=identicon&s=25 Matthew Smillie (Guest)
on 2006-02-02 01:45
(Received via mailing list)
On Feb 1, 2006, at 21:58, Malte Milatz wrote:

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

Maybe he wants octal?
A9b6a93b860020caf9d2d1d58c32478f?d=identicon&s=25 Ross Bamford (Guest)
on 2006-02-02 02: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.