From 32b53ad968e8eb06426375e0afa941a528012c6d Mon Sep 17 00:00:00 2001 From: ZedThree Date: Thu, 24 Jul 2014 20:47:38 +0200 Subject: [PATCH] Change format_currency functions to use format_integer functions --- src/string_ids.c | 76 ++++-------------------------------------------- 1 file changed, 6 insertions(+), 70 deletions(-) diff --git a/src/string_ids.c b/src/string_ids.c index 06b51543ad..2699fd9d54 100644 --- a/src/string_ids.c +++ b/src/string_ids.c @@ -1234,38 +1234,9 @@ void format_currency(char **dest, int value) *dest = dst; - value /= 10; - if (value == 0) { - *dst++ = '0'; - } else { - // Groups of three digits, right to left - groupIndex = 0; - while (value > 0) { - // Append group seperator - if (groupIndex == 3) { - groupIndex = 0; - *dst++ = ','; - } - - digit = value % 10; - value /= 10; - - *dst++ = '0' + digit; - groupIndex++; - } - } - finish = dst; - - // Reverse string - dst--; - while (*dest < dst) { - tmp = **dest; - **dest = *dst; - *dst = tmp; - (*dest)++; - dst--; - } - *dest = finish; + // value is in tens of pennies, so to get rid of + // the pence, just divide by ten + format_comma_separated_integer(dest, value/10); } void format_currency_2dp(char **dest, int value) @@ -1286,44 +1257,9 @@ void format_currency_2dp(char **dest, int value) *dest = dst; - // Two decimal places - *dst++ = '0'; - digit = value % 10; - value /= 10; - *dst++ = '0' + digit; - *dst++ = '.'; - - if (value == 0) { - *dst++ = '0'; - } else { - // Groups of three digits, right to left - groupIndex = 0; - while (value > 0) { - // Append group seperator - if (groupIndex == 3) { - groupIndex = 0; - *dst++ = ','; - } - - digit = value % 10; - value /= 10; - - *dst++ = '0' + digit; - groupIndex++; - } - } - finish = dst; - - // Reverse string - dst--; - while (*dest < dst) { - tmp = **dest; - **dest = *dst; - *dst = tmp; - (*dest)++; - dst--; - } - *dest = finish; + // value is in tens of pennies, so multiply by 10 + // to get in pounds and pence + format_comma_separated_fixed_2dp(dest, value*10); } void format_string_code(unsigned char format_code, char **dest, char **args)