1
0
mirror of https://github.com/postgres/postgres.git synced 2025-05-17 06:41:24 +03:00

Fix cash_in() to behave properly in locales where frac_digits is zero,

eg Japan.  Report and fix by Itagaki Takahiro.  Also fix CASHDEBUG printout
format for branches with 64-bit money type, and some minor comment cleanup.

Back-patch to 7.4, because it's broken all the way back.
This commit is contained in:
Tom Lane 2009-06-10 16:32:02 +00:00
parent bc4df3bf8e
commit b99bb3b218

View File

@ -9,7 +9,7 @@
* workings can be found in the book "Software Solutions in C" by * workings can be found in the book "Software Solutions in C" by
* Dale Schumacher, Academic Press, ISBN: 0-12-632360-7. * Dale Schumacher, Academic Press, ISBN: 0-12-632360-7.
* *
* $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.61 2003/09/25 06:58:03 petere Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.61.2.1 2009/06/10 16:32:02 tgl Exp $
*/ */
#include "postgres.h" #include "postgres.h"
@ -154,28 +154,22 @@ cash_in(PG_FUNCTION_ARGS)
for (;; s++) for (;; s++)
{ {
/* we look for digits as int4 as we have less */ /* we look for digits as long as we have found less */
/* than the required number of decimal places */ /* than the required number of decimal places */
if (isdigit((unsigned char) *s) && dec < fpoint) if (isdigit((unsigned char) *s) && (!seen_dot || dec < fpoint))
{ {
value = (value * 10) + *s - '0'; value = (value * 10) + (*s - '0');
if (seen_dot) if (seen_dot)
dec++; dec++;
/* decimal point? then start counting fractions... */
} }
/* decimal point? then start counting fractions... */
else if (*s == dsymbol && !seen_dot) else if (*s == dsymbol && !seen_dot)
{ {
seen_dot = 1; seen_dot = 1;
/* "thousands" separator? then skip... */
} }
else if (*s == ssymbol) /* ignore if "thousands" separator, else we're done */
{ else if (*s != ssymbol)
}
else
{ {
/* round off */ /* round off */
if (isdigit((unsigned char) *s) && *s >= '5') if (isdigit((unsigned char) *s) && *s >= '5')