Subject | Float value rounded in trigger calculation |
---|---|
Author | Nikolay Marinov |
Post date | 2007-08-13T08:25:57Z |
Hi All
using firebird 1.5(LI-V6.3.3.4870 Firebird 1.5) OS Linux Slackware 11
(kernel version 2.6.17.13)
I have master table called tOrders and detail table called tOrdersHstory.
when record is added into detail table, trigger after insert updates
master table with simple addition:
CREATE TRIGGER "tOrdersHistory_AI0" FOR "tOrdersHistory"
ACTIVE AFTER INSERT POSITION 0
AS
BEGIN
IF (UPPER(USER) NOT STARTING WITH 'REPL') THEN
UPDATE "tOrders" SET
"RdyQty" = "RdyQty" + CASE WHEN NEW."EventKind" = 1 THEN
NEW."Qty" ELSE 0 END,
"ExpQty" = "ExpQty" + CASE WHEN NEW."EventKind" = 2 THEN
NEW."Qty" ELSE 0 END,
"ArvQty" = "ArvQty" + CASE WHEN NEW."EventKind" = 3 THEN
NEW."Qty" ELSE 0 END
WHERE
"Id" = NEW."OrderId";
END
The problems is, that "sometime" tOrders is calculated with the
rounded value of new.*Qty, not with it's decimal value.
For example, i insert record with "EventKind"=1 and
"tOrdersHistory"."Qty"=4.785
The value in "tOrders"."RdyQty" is 5 instead of 4.785 - it is rounded
up to integer.
This happen not always, the most of cases are calculated correct and i
don't have idea about.
All calculated fields are members of one domain called "dQuantity" of
type float.
Thank you in advance
using firebird 1.5(LI-V6.3.3.4870 Firebird 1.5) OS Linux Slackware 11
(kernel version 2.6.17.13)
I have master table called tOrders and detail table called tOrdersHstory.
when record is added into detail table, trigger after insert updates
master table with simple addition:
CREATE TRIGGER "tOrdersHistory_AI0" FOR "tOrdersHistory"
ACTIVE AFTER INSERT POSITION 0
AS
BEGIN
IF (UPPER(USER) NOT STARTING WITH 'REPL') THEN
UPDATE "tOrders" SET
"RdyQty" = "RdyQty" + CASE WHEN NEW."EventKind" = 1 THEN
NEW."Qty" ELSE 0 END,
"ExpQty" = "ExpQty" + CASE WHEN NEW."EventKind" = 2 THEN
NEW."Qty" ELSE 0 END,
"ArvQty" = "ArvQty" + CASE WHEN NEW."EventKind" = 3 THEN
NEW."Qty" ELSE 0 END
WHERE
"Id" = NEW."OrderId";
END
The problems is, that "sometime" tOrders is calculated with the
rounded value of new.*Qty, not with it's decimal value.
For example, i insert record with "EventKind"=1 and
"tOrdersHistory"."Qty"=4.785
The value in "tOrders"."RdyQty" is 5 instead of 4.785 - it is rounded
up to integer.
This happen not always, the most of cases are calculated correct and i
don't have idea about.
All calculated fields are members of one domain called "dQuantity" of
type float.
Thank you in advance