Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > percentage in Ruby

Reply
Thread Tools

percentage in Ruby

 
 
Li Chen
Guest
Posts: n/a
 
      08-03-2007
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/.

 
Reply With Quote
 
 
 
 
Michael W. Ryder
Guest
Posts: n/a
 
      08-03-2007
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%
 
Reply With Quote
 
 
 
 
Tom Werner
Guest
Posts: n/a
 
      08-03-2007
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

 
Reply With Quote
 
Kevin Brown
Guest
Posts: n/a
 
      08-03-2007
------_=_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/Program...c_numeric.html




-----Original Message-----
From: http://www.velocityreviews.com/forums/(E-Mail 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--

 
Reply With Quote
 
Li Chen
Guest
Posts: n/a
 
      08-04-2007
Thank you all for the inputs.

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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ruby -r profile gives wrong percentage? javachallenge@gmail.com Ruby 2 12-21-2005 10:03 AM
needed percentage James MCSD 3 05-12-2004 03:34 PM
Percentage of switched vs. non-switched Ethernet Networks ??? Chris Cisco 8 04-15-2004 09:56 PM
Percentage C# vs VB.NET Justin MCSD 2 07-25-2003 11:40 PM
html image percentage issue Chris ASP .Net 7 07-24-2003 04:40 PM



Advertisments