0

I have selected same query in Oracle and t-sql, I am little confused

answers is on the contrary.

(I am interested in difference between float and decimal)

Some explanations?

T-sql:

DECLARE @A decimal(30,20);   
DECLARE @b float(10);


set @A=100
set @b=100

select 
  @A/3 + @A/3 + @A/3 as decimal,
  @b/3 + @b/3 + @b/3 as float

Oracle:

Declare flt Float;
        dcm Decimal(30,20);

Begin

  flt:=100;
  dcm:=100;

  flt:=flt/3+flt/3+flt/3;
  dcm:=dcm/3+dcm/3+dcm/3;

  dbms_output.put_line(flt);
  dbms_output.put_line(dcm);

End;
Morten
  • 398
  • 1
  • 6
  • 16
Vaso Miruashvili
  • 101
  • 1
  • 11

1 Answers1

0

FLOAT in computer science are approximate value, you can read this : Is floating point math broken?

Decimal value in TSQL are like 2 integer with a dot between, so its the exact value but require more space. I will always recommand you to work with decimal value in database.

Arnaud Peralta
  • 1,287
  • 1
  • 16
  • 20
  • if float is approximate value, why does it gives me different result in T-sql and oracle? – Vaso Miruashvili Feb 01 '19 at 10:42
  • 1
    @VasoMiruashvili - "approximate" means *not exact". So it is not surprising that different platforms with different implementations produce values which are approximately but not exactly the same. – APC Feb 01 '19 at 10:52