Sha256: 69af93f4feb59552984acac1cbed780b73216dac87842adf51f2c1e834a9ac2b
Contents?: true
Size: 1.28 KB
Versions: 19
Compression:
Stored size: 1.28 KB
Contents
# -*- encoding: utf-8 -*- # -*- frozen_string_literal: true -*- # -*- warn_indent: true -*- module UnitMeasurements module Math # Rounds quantity of the measurement. If `ndigits` is not specified, # quantity is rounded to `Integer`. # # @example # UnitMeasurements::Weight.new(1, :g).convert_to(:st).round(4) # => 0.0002 st # # @param [Integer] ndigits # # @return [Measurement] def round(ndigits = 0) self.class.new(quantity.round(ndigits), unit) end # Returns absolute value of the measurement quantity. # # @example # UnitMeasurements::Length.new(-17.625, :m).abs # => 17.625 m # # @return [Measurement] def abs self.class.new(quantity.abs, unit) end # Rounds quantity of the measurement to next lower integer. # # @example # UnitMeasurements::Length.new(17.625, :m).floor # => 17 m # # @return [Measurement] def floor(*args) self.class.new(quantity.floor(*args), unit) end # Rounds quantity of the measurement to next higher integer. # # @example # UnitMeasurements::Length.new(17.625, :m).ceil # => 18 m # # @return [Measurement] def ceil(*args) self.class.new(quantity.ceil(*args), unit) end end end
Version data entries
19 entries across 19 versions & 1 rubygems