I was trying to divide 3 by 5 (3/5) and I never got the correct result. I got back 0 all the time which is obviously not correct. But when I did 6/2 I got back 3. So when I researched a little I found out that it defaults to integer division in Ruby. That means it doesn't divide the integer if the resultant is going to be a float. So I had to do this: 3.to_f/5.to_f.
An interesting discussion about this point:
http://use.perl.org/comments.pl?sid=33948&cid=52175
Notes to self
Monday, March 10, 2008
Subscribe to:
Post Comments (Atom)
Blog Archive
-
▼
2008
(51)
-
▼
March
(12)
- Generating unique random numbers
- Ignoring files in SVN
- alias_method for class methods
- Loading fixtures separately
- to_yaml
- Types of forms in Rails
- Date and Time Functions in MySQL
- Rails Gotchas: Routes
- Integer division
- Column type mappings for databases
- Instlling a specific version of a gem
- and (&&) operand
-
▼
March
(12)
No comments:
Post a Comment