| Module | Globalize::CoreExtensions::Float |
| In: |
vendor/plugins/globalize/lib/globalize/localization/core_ext.rb
|
Returns the integer in String form, according to the rules of the currently active locale.
Example: 123456.localize -> 123.456 (German locale)
# File vendor/plugins/globalize/lib/globalize/localization/core_ext.rb, line 94
94: def localize
95: str = self.to_s
96: if str =~ /^[\d\.]+$/
97: if Locale.active?
98: active_locale = Locale.active
99: delimiter = active_locale.thousands_sep
100: decimal = active_locale.decimal_sep
101: number_grouping_scheme = active_locale.number_grouping_scheme
102: end
103: delimiter ||= ','
104: decimal ||= '.'
105: number_grouping_scheme ||= :western
106:
107: int, frac = str.split('.')
108: number_grouping_scheme == :indian ?
109: int.gsub!(/(\d)(?=((\d\d\d)(?!\d))|((\d\d)+(\d\d\d)(?!\d)))/) { |match|
110: match + delimiter} :
111: int.gsub!(/(\d)(?=(\d\d\d)+(?!\d))/) { |match| match + delimiter }
112: int + decimal + frac
113: else
114: str
115: end
116: end