Class: Numeric

Inherits:
Object
  • Object
show all
Extended by:
FatCore::Numeric::ClassMethods
Includes:
FatCore::Numeric
Defined in:
lib/fat_core/numeric.rb,
lib/fat_core/patches.rb,
lib/fat_core/patches.rb
more...

Instance Method Summary collapse

Instance Method Details

#commas(places = nil) ⇒ String Originally defined in module FatCore::Numeric

Convert this number into a string and insert grouping commas into the whole number part and round the decimal part to places decimal places, with the default number of places being zero for an integer and 4 for a non-integer. The fractional part is padded with zeroes on the right to come out to places digits after the decimal place.

Examples:

9324089.56.commas #=> '9,324,089.56'
88883.14159.commas #=>'88,883.1416'
88883.14159.commas(2) #=>'88,883.14'

Parameters:

  • places (Integer) (defaults to: nil)

    number of decimal place to round to

Returns:

#group(places = nil, delim = ',') ⇒ String Originally defined in module FatCore::Numeric

Convert this number into a string and insert grouping delimiter character, delim into the whole number part and round the decimal part to places decimal places, with the default number of places being zero for an integer and 4 for a non-integer. The fractional part is padded with zeroes on the right to come out to places digits after the decimal place. This is the same as #commas, but allows the delimiter to be any string.

Examples:

9324089.56.group          #=> '9,324,089.56'
9324089.56.group(4)       #=> '9,324,089.5600'
88883.14159.group         #=>'88,883.1416'
88883.14159.group(2)      #=>'88,883.14'
88883.14159.group(2, '_') #=>'88_883.14'

Parameters:

  • places (Integer) (defaults to: nil)

    number of decimal place to round to

  • delim (String) (defaults to: ',')

    use delim as group separator

Returns:

#int_if_wholeNumeric, Integer Originally defined in module FatCore::Numeric

Return an Integer type, but only if the fractional part of self is zero; otherwise just return self.

Examples:

45.98.int_if_whole #=> 45.98
45.000.int_if_whole #=> 45

Returns:

#negative?Boolean

Returns:

  • (Boolean)
[View source]

12
13
14
# File 'lib/fat_core/patches.rb', line 12

def negative?
  self < 0
end

#positive?Boolean

Returns:

  • (Boolean)
[View source]

4
5
6
# File 'lib/fat_core/patches.rb', line 4

def positive?
  self > 0
end

#secs_to_hmsString Originally defined in module FatCore::Numeric

Convert self, regarded as a number of seconds, into a string of the form HH:MM:SS.dd, that is to hours, minutes and seconds and fractions of seconds.

Examples:

5488.secs_to_hms #=> "01:31:28"

Returns:

  • (String)

    formatted as HH:MM:SS.dd

#signumInteger Originally defined in module FatCore::Numeric

Return the signum function for this number, i.e., 1 for a positive number, 0 for zero, and -1 for a negative number.

Examples:

-55.signum #=> -1
0.signum   #=> 0
55.signum  #=> 1

Returns:

  • (Integer)

    -1, 0, or 1 for negative, zero or positive self

#tex_quoteObject Originally defined in module FatCore::Numeric

Quote self for use in TeX documents. Since number components are not special to TeX, this just applies #to_s

#whole?Boolean Originally defined in module FatCore::Numeric

Return whether this is a whole number.

Examples:

23.45.whole? #=> false
23.whole?    #=> true

Returns:

  • (Boolean)

    is self whole?