diff options
author | rubidium <rubidium@openttd.org> | 2007-10-20 14:51:09 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2007-10-20 14:51:09 +0000 |
commit | 8212088c03c0a0af451f734391699e5dab8d8608 (patch) | |
tree | 28fbe813d418b83e119aa615200f98b20ba520c8 /src/strings.cpp | |
parent | 54369cba0f9d1cda2d40752eb337d153b3b6775f (diff) | |
download | openttd-8212088c03c0a0af451f734391699e5dab8d8608.tar.xz |
(svn r11312) -Codechange: implement a overflow safe integer and use that for money and don't misuses CommandCost to have a overflow safe integer. Based on a patch by Noldo.
Diffstat (limited to 'src/strings.cpp')
-rw-r--r-- | src/strings.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/strings.cpp b/src/strings.cpp index a82bdd15a..393f45f11 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -331,15 +331,15 @@ static char *FormatTinyDate(char *buff, Date date, const char* last) static char *FormatGenericCurrency(char *buff, const CurrencySpec *spec, Money number, bool compact, const char* last) { - const char* multiplier = ""; + /* We are going to make number absolute for printing, so + * keep this piece of data as we need it later on */ + bool negative = number < 0; + const char *multiplier = ""; char buf[40]; - char* p; + char *p; int j; - /* Multiply by exchange rate, but do it safely. */ - CommandCost cs(number); - cs.MultiplyCost(spec->rate); - number = cs.GetCost(); + number *= spec->rate; /* convert from negative */ if (number < 0) { @@ -374,7 +374,7 @@ static char *FormatGenericCurrency(char *buff, const CurrencySpec *spec, Money n *--p = spec->separator; j = 3; } - *--p = '0' + number % 10; + *--p = '0' + (char)(number % 10); } while ((number /= 10) != 0); buff = strecpy(buff, p, last); @@ -385,7 +385,7 @@ static char *FormatGenericCurrency(char *buff, const CurrencySpec *spec, Money n * The only remaining value is 1 (prefix), so everything that is not 0 */ if (spec->symbol_pos != 0) buff = strecpy(buff, spec->suffix, last); - if (cs.GetCost() < 0) { + if (negative) { if (buff + Utf8CharLen(SCC_PREVIOUS_COLOUR) > last) return buff; buff += Utf8Encode(buff, SCC_PREVIOUS_COLOUR); *buff = '\0'; |