Class: Float

Inherits:
Object show all
Defined in:
lib/roebe/core/float.rb

Overview

#

Instance Method Summary collapse

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_celsiusObject

#

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_fahrenheitObject

#

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

#±(i) ⇒ Object

#

±

Usage example:

7.52 ± 0.0752
#


15
16
17
# File 'lib/roebe/core/float.rb', line 15

def ±(i)
  [(self-i).round(4), (self+i).round(4)]
end