I personally use this method, it allow me to support I18n properly but also to only use the <sub>
container when I want the number displayed in HTML.
def formated_price(price, currency, options = {})
html = options[:html].nil? ? false : options[:html]
money = number_to_currency(price, unit: currency) || h('')
if html
separator = I18n.t('number.currency.format.separator')
tmp = money.split(separator)
tmp[1] = tmp[1].sub(/\A(\d+)(.*)\z/, content_tag(:sup, separator + '\1') + '\2') if tmp[1]
money = tmp.join.html_safe
end
money
end
if you like your currency unit to be in <sup>
as well when using HTML, you could use this instead:
def formated_price(price, currency, options = {})
html = options[:html].nil? ? false : options[:html]
if html
money = number_to_currency(price, unit: content_tag(:sup, currency)) || h('')
separator = I18n.t('number.currency.format.separator')
tmp = money.split(separator)
tmp[1] = tmp[1].sub(/\A(\d+)(.*)\z/, content_tag(:sup, separator + '\1') + '\2') if tmp[1]
money = tmp.join.html_safe
else
number_to_currency(price, unit: currency) || h('')
end
end
If you find any issue, please let me know.