Kristiyan Tsvetanov Kristiyan Tsvetanov - 4 months ago 31
Ruby Question

Rails, number to currency locale

I am trying to use

number_to_currency
.

However, I do not know how to pass the locale if it is a variable.

In other words,
number_to_currency(100, locale: :us)
works, but
number_to_currency(100, locale: @locale)
where
@locale = "us"
, does not work.

Answer

"us" is a string, you need to pass in a symbol

use @locale.to_sym

Comments