Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread Why is a Float Computed Column storing only 2 columns?
Wed, Sep 19 2012 1:26 PMPermanent Link

Barry

I have 3 columns in the table:

Net_Weight Integer
Net_Income Decimal 2 decimals
Net_Income_Per_Kg   Float

Net_Income_Per_Kg computed with:
"Net_Income_Per_Kg" FLOAT COMPUTED ALWAYS AS Net_Income / Net_Weight

Even though Net_Income_Per_Kg is a Float, it stores only 2 decimals, probably because the greatest # of decimals in the computation (Net_Income) has only 2 decimals.

Is there a way to force Net_Income_Per_Kg to store 3 decimal places?

TIA
Barry
Wed, Sep 19 2012 1:50 PMPermanent Link

Fernando Dias

Team Elevate Team Elevate

Barry,

It's because the expression (Net_Income / Net_Weight) is of type DECIMAL(19,2), as Net_Income is a DECIMAL, and Net_Weight is INTEGER - only after the computation the result is converted to FLOAT.

You can force force it to be of type DECIMAL(19,3):
"Net_Income_Per_Kg" FLOAT COMPUTED ALWAYS AS CAST(Net_Income AS DECIMAL(19,3)) / Net_Weight

or even FLOAT:

"Net_Income_Per_Kg" FLOAT COMPUTED ALWAYS AS CAST(Net_Income AS FLOAT) / Net_Weight


--
Fernando Dias
[Team Elevate]
Wed, Sep 19 2012 2:22 PMPermanent Link

Barry

Fernando,

That worked, thanks. Smile

Barry
Image