Class: Float
Overview
#
Instance Method Summary collapse
-
#ceil_to(x) ⇒ Object
# === ceil_to ========================================================================= #.
-
#floor_to(x) ⇒ Object
# === floor_to.
-
#round_to(n = 1) ⇒ Object
# === round_to.
-
#to_celsius ⇒ Object
# === to_celsius.
-
#to_fahrenheit ⇒ Object
# === to_fahrenheit.
-
#±(i) ⇒ Object
# === ±.
Instance Method Details
#ceil_to(x) ⇒ Object
#
ceil_to
#
62 63 64 |
# File 'lib/roebe/core/float.rb', line 62 def ceil_to(x) (self * 10 ** x).ceil.to_f / 10 ** x end |
#floor_to(x) ⇒ Object
#
floor_to
155555.123456.floor_to(2) # => 155555.12
#
71 72 73 |
# File 'lib/roebe/core/float.rb', line 71 def floor_to(x) (self * 10 ** x).floor.to_f / 10 ** x end |
#round_to(n = 1) ⇒ Object
#
round_to
This method will round to specified positions. Defaults to 1.
num = 138.249; num.round_to(2) # => 138.25 num = 255.550505050555555; num.round_to(5)
#
55 56 57 |
# File 'lib/roebe/core/float.rb', line 55 def round_to(n = 1) (self * 10 ** n).round.to_f / 10 ** n end |
#to_celsius ⇒ Object
#
to_celsius
Convert from “Fahrenheit” to “Celsius”.
Celsius = (Fahrenheit - 32) * 5/9
68.to_celsius # => 20.0
#
42 43 44 45 |
# File 'lib/roebe/core/float.rb', line 42 def to_celsius celsius = 5 / 9 * (self - 32.to_f) return celsius end |
#to_fahrenheit ⇒ Object
#
to_fahrenheit
“Convert” to fahrenheit.
Invocation examples:
20.to_fahrenheit
#
29 30 31 32 |
# File 'lib/roebe/core/float.rb', line 29 def to_fahrenheit fahrenheit = ( self * 9 / 5 ) + 32 return fahrenheit end |