Anda dapat membuat fungsi:
create function to_ch (value numeric, format text)
returns text language sql as $$
select rtrim(to_char(value, format), '.')
$$;
select to_ch(1.2, 'FM9999.9999'), to_ch(1, 'FM9999.9999'), to_ch(1.2212, 'FM9999.9999');
to_ch | to_ch | to_ch
-------+-------+--------
1.2 | 1 | 1.2212
(1 row)
Varian dengan format yang telah ditentukan (mungkin lebih praktis):
create function to_ch4 (value numeric)
returns text language sql as $$
select rtrim(to_char(value, 'FM9999.9999'), '.')
$$;
select to_ch4(1.2), to_ch4(1), to_ch4(1.2212);
to_ch4 | to_ch4 | to_ch4
--------+--------+--------
1.2 | 1 | 1.2212
(1 row)