Class: Float

Inherits:
Object show all
Defined in:
lib/quality_extensions/float/truncate.rb

Overview

File lib/core/facets/float/round.rb, line 17 def round_at( d ) #d=0

(self * (10.0 ** d)).round.to_f / (10.0 ** d)

end

Instance Method Summary collapse

Instance Method Details

#truncate_with_precision(d) ⇒ Object

This is the same as round_at except instead of rounding (up or down) to the nearest integer, it always truncates, rounding down to the next lowest integer.



35
36
37
# File 'lib/quality_extensions/float/truncate.rb', line 35

def truncate_with_precision(d)
 (self * (10.0 ** d)).truncate_without_precision.to_f / (10.0 ** d)
end