[PATCH] Normalize numeric/bigint scientific notation after rounding

From: 韩建桥 <hanjianqiao(at)gmail(dot)com>
To: pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: [PATCH] Normalize numeric/bigint scientific notation after rounding
Date: 2026-11-13 16:20:52
Message-ID: CAPOa_Zkc1QROJwB_JcB+f=6s1bUPRh7qr_H_=B_S-KZPa0V1DA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi hackers,

While working with PG, I found that to_char returns value that is
right but the format is wrong:
SELECT to_char(999::numeric, '9.9EEEE');
Result is: 10.0e+02, and I think the expected output should be: 1.0e+03.
With help from ChatGPT, I figured that get_str_from_var_sci()
determines the exponent
before rounding the significand. If rounding increases the
significand's absolute value to
10, the original exponent is still used. The attached patch adds a
check for this,and adjusts
the significand and the exponent.

Regards,
hanjianqiao

Attachment Content-Type Size
v1-0001-Normalize-numeric-bigint-scientific-notation-a.patch application/octet-stream 5.5 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Tomas Vondra 2026-11-13 16:57:33 Re: [PATCH] Add RetrieveInstrumentation hook for CustomScan providers
Previous Message Zsolt Parragi 2026-11-13 16:10:26 Re: pg_regress: schedule multi-line test groups