Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Float⏎
- def to_s_formatted(options = {})⏎
- decimal_places = options[:decimal_places] || 2⏎
- decimal_separator = options[:decimal_separator] || ','⏎
- thousand_separator = options[:thousand_separator] || ' '⏎
- suffix = options[:suffix]⏎
- prefix = options[:prefix]⏎
- ⏎
- snumber = "%.#{decimal_places}f" % self⏎
- snumber.gsub!('.', decimal_separator) if decimal_separator == '.'⏎
- snumber.reverse!⏎
- snumber.gsub!(%r{([0-9]{3}(?=([0-9])))}, "\\1#{thousand_separator}")⏎
- snumber.reverse!⏎
- [prefix, snumber, suffix].join(' ').strip()⏎
- end⏎
- end⏎
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement