add number currency format

This commit is contained in:
Pete Matsyburka
2025-01-17 21:08:13 +02:00
parent 37faa7ece6
commit 9aaf61e658
5 changed files with 40 additions and 2 deletions
+13 -2
View File
@@ -4,7 +4,16 @@ module NumberUtils
FORMAT_LOCALES = {
'dot' => 'de',
'space' => 'fr',
'comma' => 'en'
'comma' => 'en',
'usd' => 'en',
'eur' => 'fr',
'gbp' => 'en'
}.freeze
CURRENCY_SYMBOLS = {
'usd' => '$',
'eur' => '€',
'gbp' => '£'
}.freeze
module_function
@@ -12,7 +21,9 @@ module NumberUtils
def format_number(number, format)
locale = FORMAT_LOCALES[format]
if locale
if CURRENCY_SYMBOLS[format]
ApplicationController.helpers.number_to_currency(number, locale:, precision: 2, unit: CURRENCY_SYMBOLS[format])
elsif locale
ApplicationController.helpers.number_with_delimiter(number, locale:)
else
number