lib/money/money.rb
# Returns the amount of money as a string.
#
# @return [String]
#
# @example
#   Money.ca_dollar(100).to_s #=> "1.00"
Returns the amount of money as a string.
Returns the amount of money as a string .
def to_s
    unit, subunit = cents.abs.divmod(currency.subunit_to_unit)
    fractional    = ""
    if self.class.infinite_precision
      subunit, fractional = subunit.divmod(BigDecimal("1"))
      unit       = unit.to_i.to_s
      subunit    = subunit.to_i.to_s
      fractional = fractional.to_s("F")[2..-1]
      fractional = "" if fractional =~ /^0+$/
    else
      unit, subunit = unit.to_s, subunit.to_s
    end
    if currency.decimal_places == 0
      unit = "#{unit}#{decimal_mark}#{fractional}" unless fractional == ""
      return "-#{unit}" if cents < 0
      return unit
    end
    subunit = (("0" * currency.decimal_places) + subunit)[(-1*currency.decimal_places)..-1]
    return "-#{unit}#{decimal_mark}#{subunit}#{fractional}" if cents < 0
    "#{unit}#{decimal_mark}#{subunit}#{fractional}"
  end
def to_s unit , subunit = cents . abs . divmod ( currency . subunit_to_unit ) fractional = "" if self . class . infinite_precision subunit , fractional = subunit . divmod ( BigDecimal ( "1" ) ) unit = unit . to_i . to_s subunit = subunit . to_i . to_s fractional = fractional . to_s ( "F" ) [ 2 .. - 1 ] fractional = "" if fractional =~ / ^0+$ / else unit , subunit = unit . to_s , subunit . to_s end if currency . decimal_places == 0 unit = "#{unit}#{decimal_mark}#{fractional}" unless fractional == "" return "-#{unit}" if cents < 0 return unit end subunit = ( ( "0" * currency . decimal_places ) + subunit ) [ ( - 1 * currency . decimal_places ) .. - 1 ] return "-#{unit}#{decimal_mark}#{subunit}#{fractional}" if cents < 0 "#{unit}#{decimal_mark}#{subunit}#{fractional}" end
Returns the amount of money as a string.
Returns the amount of money as a string .
None
String
example
None