Topic: How to handle a value with decimal places in SQL

How to handle a value with decimal places, coming from a form field, which uses a comma as a separator, in an SQL statement.

                 rIndice := form1.Edit_valor.Value;
                 cbo_status := sqlexecute(
                       ' select id_tbl_status from tbl_referencias where '+
                       ' id_tbl_situacao = 1 and id_tbl_parametros = 1 and '+
                       ' CAST(REPLACE("'+floattostr(rIndice)+'", ",", ".") AS REAL) '+
                       ' between minimo and maximo');
Roberto Alencar

Re: How to handle a value with decimal places in SQL

Hi Roberto


Yes, there is such a problem.
I make a replacement in the script and substitute the value into the query.
It will be something like this:

                 rIndice := ReplaceStr(floattostr(form1.Edit_valor.Value),',','.');
                 cbo_status := sqlexecute(
                       ' select id_tbl_status from tbl_referencias where '+
                       ' id_tbl_situacao = 1 and id_tbl_parametros = 1 and '+
                       ' '+rIndice+' between minimo and maximo');

If you do not use a thousand separator, you can simplify it.

rIndice := ReplaceStr(form1.Edit_valor.Text,',','.');

Re: How to handle a value with decimal places in SQL

sparrow wrote:

Hi Roberto


Yes, there is such a problem.
I make a replacement in the script and substitute the value into the query.
It will be something like this:

                 rIndice := ReplaceStr(floattostr(form1.Edit_valor.Value),',','.');
                 cbo_status := sqlexecute(
                       ' select id_tbl_status from tbl_referencias where '+
                       ' id_tbl_situacao = 1 and id_tbl_parametros = 1 and '+
                       ' '+rIndice+' between minimo and maximo');

If you do not use a thousand separator, you can simplify it.

rIndice := ReplaceStr(form1.Edit_valor.Text,',','.');

Sparrow, tank you!

Roberto Alencar