Convert a number to a letter postgresql i have a function that convert a number to a letter.
i want to optimise this function. see query: https://dbfiddle.uk/?rdbms=postgres_12&amp;fiddle=2586d3e0b98df1c899defc7b4078e1ef
i want to have decimal part also.
now this function just return integer part.
example:
If i have 203.145, I want to get in letter 'Two hundred three point one hundred forty-five',
Now this function just return 'Two hundred three'
Query uses:
CREATE OR REPLACE FUNCTION nombreenlettre1(
    nombre numeric)
    RETURNS text
    LANGUAGE 'plpgsql'
    COST 100
    VOLATILE STRICT PARALLEL UNSAFE
AS $BODY$
/* 
  Converti un nombre en lettre

  Exemple :  SELECT nombreenlettre(5423);
             cinq mille quatre cent vingt trois
 */
DECLARE
 unite text[]='{&quot;un&quot;,&quot;deux&quot;,&quot;trois&quot;,&quot;quatre&quot;,&quot;cinq&quot;,&quot;six&quot;,
                &quot;sept&quot;,&quot;huit&quot;,&quot;neuf&quot;,&quot;dix&quot;,&quot;onze&quot;,&quot;douze&quot;,
                &quot;treize&quot;,&quot;quatorze&quot;,&quot;quinze&quot;,&quot;seize&quot;}';
 dizaine text[] ='{&quot;vingt&quot;,&quot;trente&quot;,&quot;quarante&quot;,&quot;cinquante&quot;,
                   &quot;soixante&quot;,&quot;&quot;,&quot;quatre-vingt&quot;}';
 coefs text[] ='{&quot;cent&quot;,&quot;mille&quot;,&quot;million&quot;,&quot;milliard&quot;}';
 temps text;
 c int2;
 d int2;
 u int2;
 coef int2 = 0;
 i int2;
 neg boolean;
 resultat text = '';
 n bigint;
BEGIN
  n:=nombre;
  
  IF n=0 THEN
   return 'zéro';
  END IF;

  neg:=n&lt;0;
  IF neg=true THEN
    n:=-n;
  END IF;

  LOOP
   u:=n%10;
   n:=n/10;
   d:=n%10;
   n:=n/10; 
   IF d in (1,7,9) THEN
     d:=d-1;
     u:=u+10;
   END IF;
   temps:='';
   IF d&gt;1 THEN
    temps:=' '||dizaine[d-1];
    IF (d&lt;8) and ((u=1) or (u=11)) THEN
     temps:=temps||' et';
    END IF;
   END IF;
   IF u&gt;16 THEN
    temps:=temps||' '||unite[10];
    u:=u-10;
   END IF;
   IF u&gt;0 THEN
    temps:=temps||' '||unite[u];
   END IF;
   IF (resultat='') and (d=8) and (u=0) THEN
    resultat:='s';
   END IF;
   resultat:=temps||resultat;
   c:=n%10;
   n:=n/10;
   IF c&gt;0 then
    temps:='';
    IF c&gt;1 THEN
     temps:=' '||unite[c]||temps;
    END IF;
    temps:=temps||' '||coefs[1];
    IF (resultat='') and (c&gt;1) THEN
     resultat:='s';
    END IF;
    resultat:=temps||resultat;
   END IF;
   IF n&gt;0 THEN
    coef:=coef+1;
    i:=n%1000;
    IF (i&gt;1) and (coef&gt;1) THEN
     resultat:='s'||resultat;
    END IF;
    IF i&gt;0 THEN
     resultat:=' '||coefs[coef+1]||resultat;
    END IF;
    IF (i=1) and (coef=1) THEN
     n:=n-1;
    END IF;
   END IF;
   EXIT WHEN n=0;
  END LOOP;

  IF neg THEN
   resultat:='moins'||resultat;
  END IF;
  
  return resultat;
END;
$BODY$;

select nombreenlettre1(2053.234)
you can convert in case you have floationg number in two parts , integer and floating and double call your function.
in fact the result you need for 2053.234 is
select concat(nombreenlettre1(2053), 'point', select nombreenlettre1(234))

you need just to wrap your function with a substr of your first float to get two degits.