Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. class Float⏎
  2. def to_s_formatted(options = {})⏎
  3. decimal_places = options[:decimal_places] || 2⏎
  4. decimal_separator = options[:decimal_separator] || ','⏎
  5. thousand_separator = options[:thousand_separator] || ' '⏎
  6. suffix = options[:suffix]⏎
  7. prefix = options[:prefix]⏎
  8. snumber = "%.#{decimal_places}f" % self⏎
  9. snumber.gsub!('.', decimal_separator) if decimal_separator == '.'⏎
  10. snumber.reverse!⏎
  11. snumber.gsub!(%r{([0-9]{3}(?=([0-9])))}, "\\1#{thousand_separator}")⏎
  12. snumber.reverse!⏎
  13. [prefix, snumber, suffix].join(' ').strip()⏎
  14. end⏎
  15. end⏎
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement