[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: [noob question] convert 7 in 07

Dan Diebolt

4/22/2009 10:59:00 AM

[Note: parts of this message were removed to make it a legal post.]

irb(main):001:0> n=7
=> 7
irb(main):002:0> "%02d" % n
=> "07"

--- On Wed, 4/22/09, Paul A. <cyril.staff@gmail.com> wrote:
From: Paul A. <cyril.staff@gmail.com>
Subject: [noob question] convert 7 in 07
To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
Date: Wednesday, April 22, 2009, 6:39 AM

Hi,

I would like to display numbers with a 0 before when there is only one
char.
For exemple if I gets the number 4, I would like to return 04.

After looking methods on
http://www.ruby-doc.org/core/classes/F..., I don't see how to
process. Of cours it is possible to convert a number into string and
after add a 0, but it's not very friendly.

Thanks for ideas
--
Posted via http://www.ruby-....


2 Answers

Mark Thomas

4/22/2009 11:47:00 AM

0

On Apr 22, 6:58 am, "DanDiebolt.exe" <dandieb...@yahoo.com> wrote:
> [Note:  parts of this message were removed to make it a legal post.]
>
> irb(main):001:0> n=7
> => 7
> irb(main):002:0> "%02d" % n
> => "07"
>
> --- On Wed, 4/22/09, Paul A. <cyril.st...@gmail.com> wrote:
> From: Paul A. <cyril.st...@gmail.com>
> Subject: [noob question] convert 7 in 07
> To: "ruby-talk ML" <ruby-t...@ruby-lang.org>
> Date: Wednesday, April 22, 2009, 6:39 AM
>
> Hi,
>
> I would like to display numbers with a 0 before when there is only one
> char.
> For exemple if I gets the number 4, I would like to return 04.
>
> After looking methods onhttp://www.ruby-doc.org/core/classes/F..., I don't see how to
> process.

Dan's suggestion is the simplest. But I want to point out that you can
add a Fixnum method yourself, if you are so inclined:

class Fixnum
def to_formatted_s
"%02d" % self
end
end

puts 7.to_formatted_s

jtees4

10/18/2011 2:49:00 PM

0

On Sat, 15 Oct 2011 17:28:47 -0700 (PDT), "who?"
<yourimageunreels@sbcglobal.net> wrote:

>On Oct 15, 12:48?pm, jtees4 <jte...@hotmail.com> wrote:
>> On Fri, 14 Oct 2011 16:58:01 -0700 (PDT), "who?"
>>
>> <yourimageunre...@sbcglobal.net> wrote:
>>
>> > ?I love it.
>>
>> > ?http://www.youtube.com/watch?v=JkttcytY8to&featu...
>>
>> Not my kind of music...but I can't say anything bad about it...it
>> brings back such great memories of my Mom! Herb Alpert, Al Hirt,
>> Engelbert...all of 'em.
>> ********http://www.soundclick.com/bands/default.cfm?ban...
>
>I'm not sure whose generation he belonged to. He wasn't
>in the 40's, my parents generation. I suppose he was of
>my generation of the 60's...although the music sounds
>like music my parents might have listened to. I wasn't
>even aware of who Herb Alpert was until I was 13 in 1968,
>and then I became a huge fan of about half of all the
>albums. I hated that Mexican music on the other half.

My Mom listened to him in the 60's, but as kids/teens they grew up
more with Sinatra, and Big Band stuff which my Dad loved. I was born
in 58. I would have been listening to The Beatles at that time. My
parent's didn't hate The Beatles. I remember my Dad also liked
Bohemian Rhapsody....OK next decade....but he like it.
********
http://www.soundclick.com/bands/default.cfm?ban...