Terbium-135

Terbium-135

Ex_cldr.number: currency with a default symbol for the particular locale

I’m struggling to get a ‘default currency symbol’ for the actual locale used. Perhaps it is wrong to assume that there is such a thing for a certain region/country?

Using the :currency format just gives the number but without a currency symbol:

Cldr.Number.to_string 1234.31, format: :currency, locale: "de"
{:ok, "1.234,31"}

Explicitly specifying the currency gives the desired result:

Cldr.Number.to_string 1345, currency: :EUR, locale: "de"
{:ok, "1.345,00 €"}

Can :EUR somehow be derived from the given locale?

My Cldr config is as follows:

defmodule Backend.Cldr do
  use Cldr,
    locales: ["de", "en"],
    default_locale: "en",
    json_library: Jason,
    gettext: Backend.Gettext,
    data_dir: "./priv/cldr",
    otp_app: :backend,
    precompile_number_formats: ["¤¤#.##0,##"],
    providers: [Cldr.Number, Cldr.Unit, Cldr.List, Cldr.Calendar, Cldr.DateTime],
    generate_docs: true
end

Marked As Solved

kip

kip

ex_cldr Core Team

My preference is typically to derive everything possible from the language tag since that expresses the users preferences. But of course not everyone agrees with that. Part of the rational is that for a given language (like “de”) a territory can always be derived. Typically it is the territory that has the highest population of speakers of that language.

# What is the derived territory for "de"?
iex> {:ok, locale} = Cldr.validate_locale("de")
{:ok, #Cldr.LanguageTag<de [validated]>}
iex> locale.territory
:DE
# And each territory has one (or none) current currency:
iex> Cldr.Currency.current_currency_for_territory locale.territory
:EUR

So in that respect I think its quite “clean” and consistent.

The functions that can help most commonly are:

iex> Cldr.Currency.current_currency_for_territory "de"
:EUR
iex> Cldr.Currency.currency_from_locale "de-AT"
:EUR

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
dokuzbir
Hello, I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these buyer = %{ id: ...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
mathew4509
I have a list say x = ["23gh", "56kh", "97mh"] I would like to pass each element to Val in each iteration. Say, in iteration 1 -------...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New

Other popular topics Top

belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New

We're in Beta

About us Mission Statement