Skip to content

Commit

Permalink
Do not add cent unit if symbol for local currency is "$" (issue #222)…
Browse files Browse the repository at this point in the history
…; Do not use "£" for GBP if symbol for local currency is "£"
  • Loading branch information
hanna-kn committed Sep 11, 2020
1 parent 801a3c4 commit 6b16636
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions libqalculate/Calculator-definitions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,8 @@ int Calculator::loadDefinitions(const char* file_name, bool is_user_defs, bool c
nodes.resize(1);

Unit *u_usd = getUnit("USD");
Unit *u_gbp = getUnit("GBP");
bool b_remove_cent = false;

while(true) {
if(!in_unfinished) {
Expand Down Expand Up @@ -1838,7 +1840,7 @@ int Calculator::loadDefinitions(const char* file_name, bool is_user_defs, bool c
else i++;
}
}
if(au->countNames() == 0) {
if(au->countNames() == 0 || (b_remove_cent && au->firstBaseUnit() == u_usd && au->hasName("cent"))) {
au->destroy();
au = NULL;
} else {
Expand Down Expand Up @@ -2040,21 +2042,25 @@ int Calculator::loadDefinitions(const char* file_name, bool is_user_defs, bool c
BUILTIN_NAMES_2
}
ITEM_SET_DTH
if(u == u_usd && !is_user_defs && !b_ignore_locale) {
if((u == u_usd || u == u_gbp) && !is_user_defs && !b_ignore_locale) {
struct lconv *lc = localeconv();
if(lc) {
string local_currency = lc->int_curr_symbol;
remove_blank_ends(local_currency);
if(!u->hasName(local_currency)) {
local_currency = lc->currency_symbol;
remove_blank_ends(local_currency);
if(local_currency == "$") {
if(u == u_usd && local_currency == "$") {
b_remove_cent = true;
size_t index = u->hasName("$");
if(index > 0) u->removeName(index);
index = u->hasName("dollar");
if(index > 0) u->removeName(index);
index = u->hasName("dollars");
if(index > 0) u->removeName(index);
} else if(u == u_gbp && local_currency == "£") {
size_t index = u->hasName("£");
if(index > 0) u->removeName(index);
}
}
}
Expand Down

0 comments on commit 6b16636

Please sign in to comment.