Method: RSpec::Core::Formatters::Helpers.format_seconds
- Defined in:
- lib/rspec/core/formatters/helpers.rb
permalink .format_seconds(float, precision = nil) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Formats seconds to have 5 digits of precision with trailing zeros removed if the number is less than 1 or with 2 digits of precision if the number is greater than zero.
The precision used is set in SUB_SECOND_PRECISION and DEFAULT_PRECISION.
60 61 62 63 64 65 |
# File 'lib/rspec/core/formatters/helpers.rb', line 60 def self.format_seconds(float, precision=nil) return '0' if float < 0 precision ||= (float < 1) ? SUB_SECOND_PRECISION : DEFAULT_PRECISION formatted = "%.#{precision}f" % float strip_trailing_zeroes(formatted) end |