Module: Shipindo::Helpers::RupiahToFloat

Included in:
String
Defined in:
lib/shipindo/helpers/rupiah_to_float.rb

Instance Method Summary collapse

Instance Method Details

#rupiah_to_float(options = {}) ⇒ Object Also known as: rp_to_f

convert rupiah string to float

Parameters:

  • options (Hash) (defaults to: {})

    conversion options

Options Hash (options):

  • :prefix (String) — default: "Rp."

    prefix to remove

  • :thousand_separator (String) — default: "."

    separator for thousands

  • :cent_separator (String) — default: ","

    separator for cents



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/shipindo/helpers/rupiah_to_float.rb', line 9

def rupiah_to_float(options={})
  options[:prefix]             ||= "Rp."
  options[:thousand_separator] ||= "."
  options[:cent_separator]     ||= ","

  text = self.gsub(options[:prefix],"").gsub(options[:thousand_separator],"")
  if text.include?(options[:cent_separator]) && options[:cent_separator] != "."
    text = text.gsub(options[:cent_separator], ".")
  end
  text.to_f
end