percentage in Ruby

Discussion in 'Ruby' started by Li Chen, Aug 3, 2007.

  1. Li Chen

    Li Chen Guest

    Hi all,

    How to write percentage in Ruby, for instance 1.2%? Do I have to change
    it to 0.012 before I apply other operation on it? It looks like "%" is
    used for other purpose in Ruby.

    Thanks,

    Li
    --
    Posted via http://www.ruby-forum.com/.
     
    Li Chen, Aug 3, 2007
    #1
    1. Advertising

  2. Li Chen wrote:
    > Hi all,
    >
    > How to write percentage in Ruby, for instance 1.2%? Do I have to change
    > it to 0.012 before I apply other operation on it? It looks like "%" is
    > used for other purpose in Ruby.
    >
    > Thanks,
    >
    > Li


    Try printf("%2.2f\%", 1.2) ==> displays 1.20%
     
    Michael W. Ryder, Aug 3, 2007
    #2
    1. Advertising

  3. Li Chen

    Tom Werner Guest

    Li Chen wrote:
    > Hi all,
    >
    > How to write percentage in Ruby, for instance 1.2%? Do I have to change
    > it to 0.012 before I apply other operation on it? It looks like "%" is
    > used for other purpose in Ruby.
    >
    > Thanks,
    >
    > Li
    >

    Yes, % is the modulo operator, so 1.2 percent would indeed be best
    represented as 0.012 in your code.

    Tom
     
    Tom Werner, Aug 3, 2007
    #3
  4. Li Chen

    Kevin Brown Guest

    ------_=_NextPart_001_01C7D620.856721C6
    Content-Type: text/plain;
    charset="iso-8859-1"
    Content-Transfer-Encoding: quoted-printable


    % is the modulo operator
    http://www.ruby-doc.org/docs/ProgrammingRuby/html/ref_c_numeric.html




    -----Original Message-----
    From: on behalf of Li Chen
    Sent: Fri 8/3/2007 6:03 PM
    To: ruby-talk ML
    Subject: percentage in Ruby
    =20
    Hi all,

    How to write percentage in Ruby, for instance 1.2%? Do I have to change
    it to 0.012 before I apply other operation on it? It looks like "%" is
    used for other purpose in Ruby.

    Thanks,

    Li
    --=20
    Posted via http://www.ruby-forum.com/.



    ------_=_NextPart_001_01C7D620.856721C6--
     
    Kevin Brown, Aug 3, 2007
    #4
  5. Li Chen

    Li Chen Guest

    Li Chen, Aug 4, 2007
    #5
    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. Chris

    html image percentage issue

    Chris, Jul 23, 2003, in forum: ASP .Net
    Replies:
    7
    Views:
    2,321
    John Saunders
    Jul 24, 2003
  2. fake ID
    Replies:
    1
    Views:
    14,661
  3. fake ID
    Replies:
    0
    Views:
    610
    fake ID
    Feb 10, 2006
  4. Stig Christiansen

    Tomcat, mod_jk, percentage character in URI?

    Stig Christiansen, Sep 8, 2004, in forum: Java
    Replies:
    0
    Views:
    447
    Stig Christiansen
    Sep 8, 2004
  5. Replies:
    2
    Views:
    111
    Robert Klemme
    Dec 21, 2005
Loading...

Share This Page