Sha256: e5be7e627f616fcd09554f2098a3b58cc8bac49478b64fa175a5a050b0c9354d

Contents?: true

Size: 375 Bytes

Versions: 24

Compression:

Stored size: 375 Bytes

Contents

module Fitting
  class Statistics
    class Percent
      def initialize(divider, dividend)
        @divider = divider
        @dividend = dividend
      end

      def to_f
        return 0.to_f if @divider.zero?
        (@dividend.to_f / @divider.to_f * 100.0).round(2)
      end

      def to_s
        "#{@dividend} (#{to_f}% of #{@divider})"
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
fitting-2.5.0 lib/fitting/statistics/percent.rb
fitting-2.4.1 lib/fitting/statistics/percent.rb
fitting-2.4.0 lib/fitting/statistics/percent.rb
fitting-2.3.0 lib/fitting/statistics/percent.rb