13
13
* this version handles 64 bit numbers and so can hold values up to
14
14
* $92,233,720,368,547,758.07.
15
15
*
16
- * $PostgreSQL: pgsql/src/backend/utils/adt/cash.c,v 1.75 2007/11/23 19:54:39 momjian Exp $
16
+ * $PostgreSQL: pgsql/src/backend/utils/adt/cash.c,v 1.76 2007/11/24 15:28:02 momjian Exp $
17
17
*/
18
18
19
19
#include "postgres.h"
@@ -148,7 +148,11 @@ cash_in(PG_FUNCTION_ARGS)
148
148
fpoint = 2 ; /* best guess in this case, I think */
149
149
150
150
dsymbol = ((* lconvert -> mon_decimal_point != '\0' ) ? * lconvert -> mon_decimal_point : '.' );
151
- ssymbol = ((* lconvert -> mon_thousands_sep != '\0' ) ? * lconvert -> mon_thousands_sep : ',' );
151
+ if (* lconvert -> mon_thousands_sep != '\0' )
152
+ ssymbol = * lconvert -> mon_thousands_sep ;
153
+ else
154
+ /* ssymbol should not equal dsymbol */
155
+ ssymbol = (dsymbol != ',' ) ? ',' : '.' ;
152
156
csymbol = ((* lconvert -> currency_symbol != '\0' ) ? lconvert -> currency_symbol : "$" );
153
157
psymbol = ((* lconvert -> positive_sign != '\0' ) ? * lconvert -> positive_sign : '+' );
154
158
nsymbol = ((* lconvert -> negative_sign != '\0' ) ? lconvert -> negative_sign : "-" );
@@ -293,20 +297,20 @@ cash_out(PG_FUNCTION_ARGS)
293
297
if (mon_group <= 0 || mon_group > 6 )
294
298
mon_group = 3 ;
295
299
296
- ssymbol = ((* lconvert -> mon_thousands_sep != '\0' ) ? * lconvert -> mon_thousands_sep : ',' );
297
300
convention = lconvert -> n_sign_posn ;
298
301
dsymbol = ((* lconvert -> mon_decimal_point != '\0' ) ? * lconvert -> mon_decimal_point : '.' );
302
+ if (* lconvert -> mon_thousands_sep != '\0' )
303
+ ssymbol = * lconvert -> mon_thousands_sep ;
304
+ else
305
+ /* ssymbol should not equal dsymbol */
306
+ ssymbol = (dsymbol != ',' ) ? ',' : '.' ;
299
307
csymbol = ((* lconvert -> currency_symbol != '\0' ) ? lconvert -> currency_symbol : "$" );
300
308
nsymbol = ((* lconvert -> negative_sign != '\0' ) ? lconvert -> negative_sign : "-" );
301
309
302
310
point_pos = LAST_DIGIT - points ;
303
311
304
- /* allow more than three decimal points and separate them */
305
- if (ssymbol )
306
- {
307
- point_pos -= (points - 1 ) / mon_group ;
308
- ssymbol_position = point_pos % (mon_group + 1 );
309
- }
312
+ point_pos -= (points - 1 ) / mon_group ;
313
+ ssymbol_position = point_pos % (mon_group + 1 );
310
314
311
315
/* we work with positive amounts and add the minus sign at the end */
312
316
if (value < 0 )
@@ -333,7 +337,8 @@ cash_out(PG_FUNCTION_ARGS)
333
337
strncpy ((buf + count - strlen (csymbol ) + 1 ), csymbol , strlen (csymbol ));
334
338
count -= strlen (csymbol ) - 1 ;
335
339
336
- if (buf [LAST_DIGIT ] == ',' )
340
+ /* XXX What does this do? It seems to duplicate the last character. */
341
+ if (buf [LAST_DIGIT ] == ssymbol )
337
342
buf [LAST_DIGIT ] = buf [LAST_PAREN ];
338
343
339
344
/* see if we need to signify negative amount */
0 commit comments