add number currency format
This commit is contained in:
+13
-2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user