Re: [PATCH] Don't truncate integer part in to_char for 'FM99.'
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Marti Raudsepp <marti@juffo.org>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2011-09-07T18:37:27Z
Lists: pgsql-hackers
Marti Raudsepp <marti@juffo.org> writes: > This patch fixes an edge case bug in the numeric to_char() function. > When the numeric to_char format used fillmode (FM), didn't contain 0s > and had a trailing dot, the integer part of the number was truncated in > error. > to_char(10, 'FM99.') used to return '1', after this patch it will return '10' Hmm. I agree that this is a bug, but the proposed fix seems like a bit of a kluge. Wouldn't it be better to make get_last_relevant_decnum honor its contract, that is not delete any relevant digits? I'm thinking instead of this if (!p) p = num; when there is no decimal point it should do something like if (!p) return num + strlen(num) - 1; regards, tom lane