From: Dick Davies Date: 2010-08-23T05:32:15+09:00 Subject: Re: convert 125% into 1.25? You can sort of cheat, thanks to Rubys open classes. Just add a method to Fixnum: ~:) irb >> ?> 100.class => Fixnum >> ?> class Fixnum >> def percent >> return self.to_f / 100 >> end >> end => nil >> ?> 100.percent => 1.0 >> 125.percent => 1.25 >> quit ~:) This is pretty evil, though :) It is actually possible to define a method called '%', but then you have to call it as 100.%() which looks awful. On Sat, Aug 21, 2010 at 1:58 PM, Eric MSP Veith wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Pen, > > On Saturday 21 August 2010, Pen Ttt wrote: >> irb(main):012:0> format("%.2f",125%) > > 125% is, strictly spoken, not a number, but a number plus a unit. The unit > is a character, not an integer, and this makes "125%" only valid as a string > in Ruby. You've got to remove the "%" sign before you can treat "125" as a > number. > > HTH. > >                        Eric > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.9 (GNU/Linux) > > iEYEARECAAYFAkxvzWMACgkQhS0drJ3goJJmWwCaA1o2qvv0Tf1L4bsnAw7HJ95D > xdUAoIbg/9wV+D1bdTBIUXsOL38dLqSy > =SiNK > -----END PGP SIGNATURE----- > >