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. Advertisements

  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. Advertisements

  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. Advertisements

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. TheRemedy
    Replies:
    1
    Views:
    729
    raagz
    Sep 7, 2004
  2. Ven
    Replies:
    3
    Views:
    1,572
  3. Gilbert Fine
    Replies:
    8
    Views:
    1,176
    Zentrader
    Aug 1, 2007
  4. Vitaliy
    Replies:
    1
    Views:
    701
    Peter Otten
    May 29, 2008
  5. valpa
    Replies:
    11
    Views:
    2,338
    Steven D'Aprano
    Mar 24, 2009
  6. Replies:
    0
    Views:
    469
  7. Jeff Beardsley

    A possible change to decimal.Decimal?

    Jeff Beardsley, Mar 2, 2012, in forum: Python
    Replies:
    5
    Views:
    455
    Ethan Furman
    Mar 4, 2012
  8. PERO
    Replies:
    4
    Views:
    576
    Brian McCauley
    Apr 13, 2007
Loading...