Re: Float output formatting options

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Float output formatting options
Дата
Msg-id 4535.1036423989@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Float output formatting options  ("Pedro M. Ferreira" <pfrazao@ualg.pt>)
Список pgsql-hackers
"Pedro M. Ferreira" <pfrazao@ualg.pt> writes:
> Tom Lane wrote:
>> I think a single setting extra_float_digits would be sufficient.

> Ok. Assuming,

> int extra_float_digits, default 0, min -13, max 2

> If extra_float_digits==-13 and we are outputing a float4 this results in 
> a negative value for FLT_DIG+extra_float_digits.

You would want to clamp the values passed to %g to not less than 1.
I'd favor code likeint    ndig = FLT_DIG + extra_float_digits;if (ndig < 1)    ndig = 1;sprintf(ascii, "%.*g", ndig,
num);

Probably best to do it this way with float8 too; otherwise we're
essentially wiring in the assumption that we know what DBL_DIG is.
Which is exactly what we're trying to avoid doing.
        regards, tom lane


В списке pgsql-hackers по дате отправления:

Предыдущее
От: "Pedro M. Ferreira"
Дата:
Сообщение: Re: Float output formatting options
Следующее
От: "Pedro M. Ferreira"
Дата:
Сообщение: Re: Float output formatting options