Skip to content

Commit

Permalink
Really don't override fractional digits for currency format
Browse files Browse the repository at this point in the history
  • Loading branch information
kipcole9 committed Jul 24, 2023
1 parent fb232a1 commit e31a933
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/cldr/number/formatter/decimal_formatter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -826,22 +826,22 @@ defmodule Cldr.Number.Formatter.Decimal do

def adjust_fraction_for_currency(meta, currency, :accounting, backend) do
{:ok, currency} = Currency.currency_for_code(currency, backend)
do_adjust_fraction(meta, meta.fractional_digits.max, currency.rounding)
do_adjust_fraction(meta, currency.digits, currency.rounding)
end

def adjust_fraction_for_currency(meta, currency, :cash, backend) do
{:ok, currency} = Currency.currency_for_code(currency, backend)
do_adjust_fraction(meta, meta.fractional_digits.max, currency.cash_rounding)
do_adjust_fraction(meta, currency.cash_digits, currency.cash_rounding)
end

def adjust_fraction_for_currency(meta, currency, :iso, backend) do
{:ok, currency} = Currency.currency_for_code(currency, backend)
do_adjust_fraction(meta, meta.fractional_digits.max, currency.iso_digits)
do_adjust_fraction(meta, currency.iso_digits, currency.iso_digits)
end

defp do_adjust_fraction(meta, digits, rounding) do
rounding = power_of_10(-digits) * rounding
%{meta | fractional_digits: %{max: digits, min: digits}, round_nearest: rounding}
%{meta | round_nearest: rounding}
end

# Functions to update metadata to reflect the
Expand Down
3 changes: 3 additions & 0 deletions test/support/number_format_test_data.exs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ defmodule Cldr.Test.Number.Format do
{1234.567, "1 234,57 €", [format: "#,##0.00 ¤", locale: "fr", currency: :EUR]},
{1234.567, "1 235 JPY", [format: "#,##0 ¤", locale: "fr", currency: "JPY"]},
{1234.567, "1 234,57 JPY", [format: "#,##0.00 ¤", locale: "fr", currency: "JPY"]},
{1234.567, "1 234,57 JPY", [format: "#,##0.## ¤", locale: "fr", currency: "JPY"]},
{1234.00, "1 234 JPY", [format: "#,##0.## ¤", locale: "fr", currency: "JPY"]},
{1234, "1 234 JPY", [format: "#,##0.## ¤", locale: "fr", currency: "JPY"]},

# Fraction grouping
{1234.4353244565, "1234,435 324 456 5", [format: "#,###.###,#########", locale: "pl"]},
Expand Down

0 comments on commit e31a933

Please sign in to comment.