How to format a number with optional fraction
You can use trim(trailing '.0', x::text)

SELECT trim(trailing '.0' FROM x::text)
FROM (
  VALUES (1.5),(1.0),(1.04),(1.040),(1.9594830000)
) AS t(x);
  rtrim   
----------
 1.5
 1
 1.04
 1.04
 1.959483
(5 rows)