-
Content Count
182 -
Joined
-
Last visited
-
Days Won
2
Single Status Update
-
Question for the Coders: How do you tell ruby to round up or down?
-
you have a few options:
float.floor
-rounds to the next integer towards 0, so
1.5.floor => 1
(-1.5).floor => -1
float.ceil
-rounds to the next integer away from 0, so
1.5.ceil => 2
(-1.5).ceil => -2
float.round
-just like standard rounding, if >= 0.5 round up, if < 0.5 round down, so
1.5.round = 2
1.4.round = 1
float.truncate
float.to_i
-these methods simply chop off the fractional bit, so
...
-
-
Thats exactly what I needed to know :D Thanks Kell
-