Board index » delphi » Floating Point Paradox

Floating Point Paradox


2003-09-11 06:44:44 PM
delphi75
Hi Experts,
I wonder if somebody could help me in a question.
Imagine that you have one paradox table called "Table" and you got a query
in Delphi called "Query". Now, everytime that i want my query to do an
Insert or Update, i got the "Type mismatch in expression" error.
Due to (I think) the floating values, that are separated with the ","
character.
With this code I have the Error:
Query.Sql.Add('Insert Into Table (No,Quant) Values ("1","11,56")');
Query.Sql.ExecSql;
With this one i do not
Query.Sql.Add('Insert Into Table (No,Quant) Values ("1","11.56")');
Query.Sql.ExecSql;
The only thing that changes is de decimal character. But in Delphi, the
decimal character is ",".
Is this a conflict between Delphi an Paradox ?
Can anyone help, please?
Jorge Ferreira
 
 

Re:Floating Point Paradox

Hi Experts,
I wonder if somebody could help me in a question.
Imagine that you have one paradox table called "Table" and you got a query
in Delphi called "Query". Now, everytime that i want my query to do an
Insert or Update, i got the "Type mismatch in expression" error.
Due to (I think) the floating values, that are separated with the ","
character.
With this code I have the Error:
Query.Sql.Add('Insert Into Table (No,Quant) Values ("1","11,56")');
Query.Sql.ExecSql;
With this one i do not
Query.Sql.Add('Insert Into Table (No,Quant) Values ("1","11.56")');
Query.Sql.ExecSql;
The only thing that changes is de decimal character. But in Delphi, the
decimal character is ",".
Is this a conflict between Delphi an Paradox ?
Can anyone help, please?
Jorge Ferreira
 

Re:Floating Point Paradox

For Paradox you must use the decimal separator that is specified in BDE
Administrator (see Configuration\System\Formats\Number\DecimalSeparator). By
default there is a '.'
So just change to ',' there if you want
"Jorge Ferreira" <XXXX@XXXXX.COM>сообщи?сообщила ?новостях
следующе? news:XXXX@XXXXX.COM...
Quote
Hi Experts,

I wonder if somebody could help me in a question.
Imagine that you have one paradox table called "Table" and you got a query
in Delphi called "Query". Now, everytime that i want my query to do an
Insert or Update, i got the "Type mismatch in expression" error.
Due to (I think) the floating values, that are separated with the ","
character.

With this code I have the Error:
Query.Sql.Add('Insert Into Table (No,Quant) Values ("1","11,56")');
Query.Sql.ExecSql;

With this one i do not
Query.Sql.Add('Insert Into Table (No,Quant) Values ("1","11.56")');
Query.Sql.ExecSql;

The only thing that changes is de decimal character. But in Delphi, the
decimal character is ",".

Is this a conflict between Delphi an Paradox ?

Can anyone help, please?

Jorge Ferreira




 

Re:Floating Point Paradox

"Jorge Ferreira" <XXXX@XXXXX.COM>writes
Quote
But in Delphi, the decimal character is ",".
That is wrong.
In Delphi the decimal separator is "." when you are writing code. The
compiler expects "." as the decimal separator.
When the program is running the decimal separator depends on the user's
regional settings.
These two 2 are very different things.
 

Re:Floating Point Paradox

Quote
When the program is running the decimal separator depends on the user's
regional settings.
There is special variable In Delphi - DecimalSeparator. Set it to '.' or
','. This override Regional setting.
 

Re:Floating Point Paradox

"Alexei Emanov" <XXXX@XXXXX.COM>writes
Quote
>When the program is running the decimal separator depends on the user's
>regional settings.

There is special variable In Delphi - DecimalSeparator. Set it to '.' or
','. This override Regional setting.
Correct.
But IMHO it is the responsibility of the program to adhere to the user's
choice of regional settings.
Changing DecimalSeparator should be avoided.
Imagine the chaos if different parts of the program changes the
DecimalSeparator. Oh boy, will you be in trouble.
 

Re:Floating Point Paradox

So what you're saying is that both paradox (BDE) and Delphi use the regional
settings to choose the Decimal Separator, right?
My Regional Settings are configured so the decimal separator is "," but
everytime i throw a query into paradox like this:
Insert Into Table (cod, no) values ("1","1,1")
it aalways respondes with one error: "Type mismatch in expression"
Thanx for your reply
Jorge Ferreira
"Finn Tolderlund" <XXXX@XXXXX.COM>escreveu na mensagem
Quote

"Alexei Emanov" <XXXX@XXXXX.COM>writes
news:XXXX@XXXXX.COM...
>>When the program is running the decimal separator depends on the
user's
>>regional settings.
>
>There is special variable In Delphi - DecimalSeparator. Set it to '.' or
>','. This override Regional setting.

Correct.
But IMHO it is the responsibility of the program to adhere to the user's
choice of regional settings.
Changing DecimalSeparator should be avoided.
Imagine the chaos if different parts of the program changes the
DecimalSeparator. Oh boy, will you be in trouble.
--
Finn Tolderlund


 

Re:Floating Point Paradox

I'm assuming that cod and no are numerical fields?
Then you should write
Insert Into Table (cod, no) values (1, 1.1)
--
Finn Tolderlund
"Jorge Ferreira" <XXXX@XXXXX.COM>skrev i en meddelelse
Quote
Insert Into Table (cod, no) values ("1","1,1")
it aalways respondes with one error: "Type mismatch in expression"
 

Re:Floating Point Paradox

"Finn Tolderlund" <XXXX@XXXXX.COM>escreveu na mensagem
Quote
I'm assuming that cod and no are numerical fields?
Yes they are
Quote
Then you should write
Insert Into Table (cod, no) values (1, 1.1)
So i don't need the "" right?
But my regional settings indicate that "," is the decimal separator, so i
can't do anything like:
Insert Into Table (cod, no) values (1, 1,1)
because it will thing that i have 3 parameters in values
 

Re:Floating Point Paradox

"Jorge Ferreira" <XXXX@XXXXX.COM>skrev i en meddelelse
Quote
But my regional settings indicate that "," is the decimal separator, so i
can't do anything like:
Insert Into Table (cod, no) values (1, 1,1)
because it will thing that i have 3 parameters in values
Will some please take over?
I give up...
--
Finn Tolderlund
 

Re:Floating Point Paradox

In article <XXXX@XXXXX.COM>, Jorge Ferreira writes:
Quote

But my regional settings indicate that "," is the decimal separator, so i
can't do anything like:
Insert Into Table (cod, no) values (1, 1,1)
because it will thing that i have 3 parameters in values
Rubbish (sorry). What you have is an SQL statement in a string, and that
means that the rules for SQL apply. And SQL is an US american chauvinist
language, like Delphi, so it expects floating point values to be given with
a decimal point. Same as you specify floating point values in Delphi source
files.
This is actually a problem if you compose the SQL string using Format, e.g.
query.sql.text :=
format( 'Insert Into Table (cod, no) values (%d, %f8.2)',
[ aCode, aValue ] );
since Format *will* use the language settings to convert aValue into a
string. The best way to get around that is not to build SQL statements this
way. Instead use bind variables, they are language-neutral:
query.Params.Clear;
query.sql.text :=
'Insert Into Table (cod, no) values (:cod, :no)';
query.Params.ParseSQL;
query.ParamByName('cod').AsInteger := aCode;
query.ParamByName('no' ).AsFloat := aValue;
query.Execute;
You can repeat the last three lines with new values without having to
repeat the others, and of course you can set up the SQL statement and the
parameters at design-time as well.
Peter Below (TeamB)
Use the newsgroup archives :
www.mers.com/searchsite.html
www.tamaracka.com/search.htm
groups.google.com
www.prolix.be
 

Re:Floating Point Paradox

That works Peter,
finally someone understood what was the problem...
"Peter Below (TeamB)" <XXXX@XXXXX.COM>escreveu na mensagem
Quote
In article <XXXX@XXXXX.COM>, Jorge Ferreira writes:
>
>But my regional settings indicate that "," is the decimal separator, so
i
>can't do anything like:
>Insert Into Table (cod, no) values (1, 1,1)
>because it will thing that i have 3 parameters in values

Rubbish (sorry). What you have is an SQL statement in a string, and that
means that the rules for SQL apply. And SQL is an US american chauvinist
language, like Delphi, so it expects floating point values to be given
with
a decimal point. Same as you specify floating point values in Delphi
source
files.

This is actually a problem if you compose the SQL string using Format,
e.g.

query.sql.text :=
format( 'Insert Into Table (cod, no) values (%d, %f8.2)',
[ aCode, aValue ] );

since Format *will* use the language settings to convert aValue into a
string. The best way to get around that is not to build SQL statements
this
way. Instead use bind variables, they are language-neutral:

query.Params.Clear;
query.sql.text :=
'Insert Into Table (cod, no) values (:cod, :no)';
query.Params.ParseSQL;

query.ParamByName('cod').AsInteger := aCode;
query.ParamByName('no' ).AsFloat := aValue;
query.Execute;

You can repeat the last three lines with new values without having to
repeat the others, and of course you can set up the SQL statement and the
parameters at design-time as well.



--
Peter Below (TeamB)
Use the newsgroup archives :
www.mers.com/searchsite.html
www.tamaracka.com/search.htm
groups.google.com
www.prolix.be


 

Re:Floating Point Paradox

ROFLMAO.
--
Finn Tolderlund
"Jorge Ferreira" <XXXX@XXXXX.COM>skrev i en meddelelse
Quote
That works Peter,
finally someone understood what was the problem...