how to force a decimal

Discussion in 'Ruby' started by shawn bright, Jun 20, 2008.

  1. shawn bright

    shawn bright Guest

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

    Hey there all,

    This should be simple. I need to know how to force a decimal place.

    say i wanted to do 3.5.to_s
    but i need that to be 3.50 as the string,

    how would i do this?

    thanks
     
    shawn bright, Jun 20, 2008
    #1
    1. Advertising

  2. shawn bright

    ThoML Guest

    > say i wanted to do  3.5.to_s
    > but i need that to be 3.50 as the string,


    Use String#% and friends:

    "%.2f" % 3.5
     
    ThoML, Jun 20, 2008
    #2
    1. Advertising

  3. shawn bright

    shawn bright Guest

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

    cool, thanks much !

    On Fri, Jun 20, 2008 at 1:38 PM, ThoML <> wrote:

    > > say i wanted to do 3.5.to_s
    > > but i need that to be 3.50 as the string,

    >
    > Use String#% and friends:
    >
    > "%.2f" % 3.5
    >
    >
     
    shawn bright, Jun 20, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ven
    Replies:
    3
    Views:
    1,345
  2. Gilbert Fine
    Replies:
    8
    Views:
    921
    Zentrader
    Aug 1, 2007
  3. Vitaliy
    Replies:
    1
    Views:
    492
    Peter Otten
    May 29, 2008
  4. valpa
    Replies:
    11
    Views:
    1,563
    Steven D'Aprano
    Mar 24, 2009
  5. Replies:
    0
    Views:
    306
Loading...

Share This Page