How can store exact decimal value in database

273 Views Asked by At

1 * 20/100 = 0.2

I want to store the same value in database how can i do that I have give column type as Decimal and the lenght automatically taking as (10,0)

My issue is it is storing as 0 instead of 0.2

3

There are 3 best solutions below

0
On BEST ANSWER

No datatype will store 1/3 exactly.

Your example of 20/100 implies the need for DECIMAL(..., 2), where the ... is a suitable maxinum number of digits including the 2.

Without further insight into where the numbers are coming from or how they will be used, we cannot discuss this further.

0
On

Change the limit of that field as (10,2) and then try again. It might help you.

1
On

Use type "double" (10,2) in your database.

double is type and length is 10,2 it will store like 0.20

if your want to store only single decimal digit the use 10,1

Thanks.