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.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 $
1717 */
1818
1919#include "postgres.h"
@@ -148,7 +148,11 @@ cash_in(PG_FUNCTION_ARGS)
148148 fpoint = 2 ; /* best guess in this case, I think */
149149
150150 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 != ',' ) ? ',' : '.' ;
152156 csymbol = ((* lconvert -> currency_symbol != '\0' ) ? lconvert -> currency_symbol : "$" );
153157 psymbol = ((* lconvert -> positive_sign != '\0' ) ? * lconvert -> positive_sign : '+' );
154158 nsymbol = ((* lconvert -> negative_sign != '\0' ) ? lconvert -> negative_sign : "-" );
@@ -293,20 +297,20 @@ cash_out(PG_FUNCTION_ARGS)
293297 if (mon_group <= 0 || mon_group > 6 )
294298 mon_group = 3 ;
295299
296- ssymbol = ((* lconvert -> mon_thousands_sep != '\0' ) ? * lconvert -> mon_thousands_sep : ',' );
297300 convention = lconvert -> n_sign_posn ;
298301 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 != ',' ) ? ',' : '.' ;
299307 csymbol = ((* lconvert -> currency_symbol != '\0' ) ? lconvert -> currency_symbol : "$" );
300308 nsymbol = ((* lconvert -> negative_sign != '\0' ) ? lconvert -> negative_sign : "-" );
301309
302310 point_pos = LAST_DIGIT - points ;
303311
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 );
310314
311315 /* we work with positive amounts and add the minus sign at the end */
312316 if (value < 0 )
@@ -333,7 +337,8 @@ cash_out(PG_FUNCTION_ARGS)
333337 strncpy ((buf + count - strlen (csymbol ) + 1 ), csymbol , strlen (csymbol ));
334338 count -= strlen (csymbol ) - 1 ;
335339
336- if (buf [LAST_DIGIT ] == ',' )
340+ /* XXX What does this do? It seems to duplicate the last character. */
341+ if (buf [LAST_DIGIT ] == ssymbol )
337342 buf [LAST_DIGIT ] = buf [LAST_PAREN ];
338343
339344 /* see if we need to signify negative amount */
0 commit comments