percentage in Ruby

L

Li Chen

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
 
M

Michael W. Ryder

Li said:
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%
 
T

Tom Werner

Li said:
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
 
K

Kevin Brown

------_=_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: (e-mail address removed) 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--
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top