Skip to content

Commit 2ef8c1a

Browse files
committed
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.
1 parent 09cba66 commit 2ef8c1a

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/backend/utils/adt/cash.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* this version handles 64 bit numbers and so can hold values up to
1414
* $92,233,720,368,547,758.07.
1515
*
16-
* $PostgreSQL: pgsql/src/backend/utils/adt/cash.c,v 1.80 2008/06/09 19:58:39 tgl Exp $
16+
* $PostgreSQL: pgsql/src/backend/utils/adt/cash.c,v 1.81 2009/06/10 16:31:32 tgl Exp $
1717
*/
1818

1919
#include "postgres.h"
@@ -191,23 +191,21 @@ cash_in(PG_FUNCTION_ARGS)
191191

192192
for (;; s++)
193193
{
194-
/* we look for digits as int8 as we have less */
194+
/* we look for digits as long as we have found less */
195195
/* than the required number of decimal places */
196-
if (isdigit((unsigned char) *s) && dec < fpoint)
196+
if (isdigit((unsigned char) *s) && (!seen_dot || dec < fpoint))
197197
{
198-
value = (value * 10) + *s - '0';
198+
value = (value * 10) + (*s - '0');
199199

200200
if (seen_dot)
201201
dec++;
202-
203202
}
204203
/* decimal point? then start counting fractions... */
205204
else if (*s == dsymbol && !seen_dot)
206205
{
207206
seen_dot = 1;
208-
209207
}
210-
/* not "thousands" separator? */
208+
/* ignore if "thousands" separator, else we're done */
211209
else if (*s != ssymbol)
212210
{
213211
/* round off */
@@ -236,7 +234,7 @@ cash_in(PG_FUNCTION_ARGS)
236234
result = value * sgn;
237235

238236
#ifdef CASHDEBUG
239-
printf("cashin- result is %d\n", result);
237+
printf("cashin- result is " INT64_FORMAT "\n", result);
240238
#endif
241239

242240
PG_RETURN_CASH(result);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy