Closed szewczykmira closed 7 years ago
Merging #40 into master will increase coverage by
1.48%
. The diff coverage is91.66%
.
@@ Coverage Diff @@
## master #40 +/- ##
==========================================
+ Coverage 85.63% 87.11% +1.48%
==========================================
Files 5 5
Lines 174 194 +20
Branches 21 23 +2
==========================================
+ Hits 149 169 +20
Misses 15 15
Partials 10 10
Impacted Files | Coverage Δ | |
---|---|---|
django_prices/templatetags/prices_i18n.py | 93.33% <100%> (+1.84%) |
:white_check_mark: |
django_prices/templatetags/prices.py | 83.33% <70%> (+10.6%) |
:white_check_mark: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update 74dd138...7b929f6. Read the comment docs.
Have you tested it with currencies with 0 or 3 decimal places? https://en.wikipedia.org/wiki/ISO_4217
@krzysztofwolski What would you expect to happen if the currency already has zero decimal places?
@patrys Well, it would look this same. Just wondered if it was tested after seeing tests using only USD as currency.
@krzysztofwolski it was tested with currencies with 0 decimal digits and I'll push tests with them as soon as I take care of currencies with 3 digits :)
@krzysztofwolski @patrys So for last few hours I was looking for solution how to handle normalization when currency has 3 decimal digits - and I must say - there is no pretty solution for that.
Currency formats available through babel
don't define 3 decimal digits. We can achieve that only by setting currency_digits=True
in format_currency
, but it will be always using currency's number of decimal digits (even if normalization is set to true)
Right now I have two options:
First - don't allow for price normalization when price has 3 decimal digits.
Second - make a little hack:
currency_fractions = get_currency_fraction(currency)
if currency_fractions == 3:
pattern = pattern.replace('.00', '.###')
else:
pattern = pattern.replace('.00', '.##')
What do you think?
Can't we do something like patter.replace('.00', '.' + '#' * currency_fractions)
? Does the pattern always contain .00
even when there are three digits?
I didn't find any pattern that contains three digits. I don't want to mess anything so I made issue in babel repository and I'm waiting for their response.
Babel does not provide its own data, locale data comes from official Unicode releases.
@patrys Note form Unicode about currency pattern: Note: the number of decimals will be set by programs that use CLDR to whatever is appropriate for the currency, so do not change them; keep exactly 2 decimals.
Are we sure we want to do against this note?
In this case we are the program. We already know the appropriate number of decimals so we can choose do the following:
When asked to replace two decimal zeroes with two decimal hashes and call it a day.
Always replace two decimal zeroes with either an appropriate number of decimal zeroes or an appropriate number of decimal hashes depending on the currency and whether we were asked for normalization (this is what currency_digits
does).
I'm leaning towards the latter as it seems to be the Right Thing To Do™.
Updated with second option.
@patrys can you look at it?
Allow templatetags to render price without decimal digits (if they are equal to 0). This change was suggested in issue #32
Example usage:
{% gross price normalize=True %}