#### Topic: 0.1 + 0.2 = 0.3

Good morning
A bit Friday subject.
Request

``select 0.1 + 0.2 from dual``

On oracle produces the correct answer 0.3
On Python, Java, Perl and other languages
.1 +.2
0.30000000000000004
The question arises, what difference in mechanisms of calculations in a DBMS and ?
How to write the code on  in  with caution on this problem.
By the way, Firebird too correctly calculates

``select 0.1 + 0.2 from rdb\$database``

#### Re: 0.1 + 0.2 = 0.3

DFilushin;
You still would specify data types in a case with  and with .... If in yours  it something from a series  (float) anything it is surprising.  is an approximate type. Accordingly, and the result in it will be - too approximate.
:-D

#### Re: 0.1 + 0.2 = 0.3

Schukin Anna;
For a python it typed in the console, without instructions of types, with dynes. Typification

#### Re: 0.1 + 0.2 = 0.3

``````tst&gt; select.1 +. 2 from dual;
.1 +. 2
------------
.3
tst&gt; select.1d +. 2d from dual;
.1D +. 2D
------------
3.0E-001
tst&gt; set numwidth 40
tst&gt; select.1d +. 2d from dual;
.1D +. 2D
----------------------------------------
3.0000000000000004E-001``````

#### Re: 0.1 + 0.2 = 0.3

Vyacheslav Ljubomudrov;
Here you specified type forcedly
What mechanism is used for the simple "not typified" calculation?

#### Re: 0.1 + 0.2 = 0.3

And by default NUMBER with the accuracy of 39-40 signs

``````tst&gt; set numwidth 42
tst&gt; select .0987654321098765432109876543210987654321 from dual;
.0987654321098765432109876543210987654321
------------------------------------------
.0987654321098765432109876543210987654321
tst&gt; select .09876543210987654321098765432109876543219 from dual;
.09876543210987654321098765432109876543219
------------------------------------------
.0987654321098765432109876543210987654322``````

#### Re: 0.1 + 0.2 = 0.3

Ljubomudrov wrote:

And by default NUMBER

And in PL/SQL also PLS_INTEGER.

#### Re: 0.1 + 0.2 = 0.3

Anna wrote:

Float is an approximate type. Accordingly, and the result in it will be - too approximate.

It is type a joke such was?

#### Re: 0.1 + 0.2 = 0.3

andrey_anonymous wrote:

it is passed...
It is type a joke such was?

Why a joke?  hardware type, instead of program. Because of a rough rounding off in binary numeral system also there is an inaccuracy.

#### Re: 0.1 + 0.2 = 0.3

DFilushin wrote:

the Question arises, what difference in mechanisms of calculations in a DBMS and ?
How to write the code on  in  with caution on this problem.

I have other question - as working in IT the person can not know differences binary and decimal formats? About standard IEEE 754 I will not recall.

#### Re: 0.1 + 0.2 = 0.3

IMNO wrote:

Float hardware type, instead of program. Because of a rough rounding off in binary numeral system also there is an inaccuracy.

.
Do not check - in the modern computer facilities ALL data - binary, "program" too.
However, about IEEE 754 here already reminded - ignorant would recommend to familiarize at least superficially.

#### Re: 0.1 + 0.2 = 0.3

In  the type currency approaches for money

#### Re: 0.1 + 0.2 = 0.3

andreymx wrote:

in  the type currency approaches for money

For money any implementation fixed point, the most widespread - representation in the form of whole, multiplied on 10 in an interesting level approaches.
From floating - implementation with decimal order approaches, for example - it see decimalXX from IEEE 754-2008, ISO/IEC/IEEE 60559:2011.