Skip to content

Instantly share code, notes, and snippets.

@wingrunr21
Created October 6, 2014 21:19
Show Gist options
  • Save wingrunr21/e6408f5a29ca22c40442 to your computer and use it in GitHub Desktop.
Save wingrunr21/e6408f5a29ca22c40442 to your computer and use it in GitHub Desktop.
Provides a method similar to the number_to_currency Rails helper, except that the decimal portion of the resulting formatted text is wrapped in a configurable tag (sup by default)
# This module provides a method similar to the number_to_currency
# Rails helper, except that the decimal portion of the resulting
# formatted text is wrapped in a configurable tag (sup by default)
#
# Copyright (C) 2014 Turn4 LLC
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
module CurrencyHelper
def number_to_currency_with_script(number, options = {})
separator = options.fetch(:separator, '.')
script = options.fetch(:script, :sup)
amount = number_to_currency(number, options).split(separator)
amount[-1] = content_tag(script, amount.last)
amount.join(separator).html_safe
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment