Module: Rubi18n::Formatters::Float

Included in:
Float
Defined in:
lib/rubi18n/formatters.rb

Instance Method Summary collapse

Instance Method Details

#to_ls(locale = Rubi18n::Locale.current) ⇒ Object

Returns the integer in String form, according to the rules of the locale (default currently active). It will also put real typographic minus.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rubi18n/formatters.rb', line 47

def to_ls(locale = Rubi18n::Locale.current)
  int, frac = self.to_s.split('.')
  int[0] = "" if 0 > self # Real typographic minus
  group = locale["numbers"]["group_delimiter"]
  decimal = locale["numbers"]["decimal_separator"]
  
  if "indian" == locale["numbers"]["separation"]
    int.gsub!(/(\d)(?=((\d\d\d)(?!\d))|((\d\d)+(\d\d\d)(?!\d)))/) do |match|
      match + group
    end
  else
    int.gsub!(/(\d)(?=(\d\d\d)+(?!\d))/) do |match|
      match + group
    end
  end
  int + decimal + frac
end