Latinum SourceLatinumFormattersPlainFormatter

class PlainFormatter

Formats a currency using a standard decimal notation.

Definitions

def parse(string)

Parse a string into an amount.

Signature

returns BigDecimal

The parsed amount.

Implementation

def parse(string)
	BigDecimal(string)
end

def format(amount)

Formats the amount using a general notation. e.g. "5.0 NZD".

Signature

returns String

The formatted string.

Implementation

def format(amount)
	"#{amount.to_s('F')} #{@name}"
end

def to_integral(amount)

Converts the amount directly to an integer, truncating any decimal part.

Signature

parameter amount BigDecimal

The amount to convert to an integral.

returns Integer

The converted whole number integer.

Implementation

def to_integral(amount)
	amount.to_i
end

def from_integral(amount)

Converts the amount to a decimal.

Signature

parameter amount Integer

The amount to convert to a decimal.

returns BigDecimal

The converted amount.

Implementation

def from_integral(amount)
	amount.to_d
end