sql with rounding issue

I have a problem with sql(maths).

I have a total payable given to vendor which is 33.333, and I need to divide the amount with two users. So I have select

select (16.666 * 2) from dual which gives me 33.332 that is .1 less than the total amount I have to give.

If I have this sql select (16.667 * 2) from dual, then it gives me 33.334 which .1 greater than 33.333.

How can I divide the total amount which I could equally distribute?

Thanks

Answers


I'm not sure from where are you executing your query, but it works here (SQLDeveloper, 10g):

SELECT (33.333 / 2) FROM dual;
16,6665

SELECT (16.6665 * 2) FROM dual;
33,333

Do it the other way around:

select 33.333/2

You are most likely working with the wrong column type. You should be using DECIMAL instead of e.g. FLOAT.

Here is a good summary: http://lists.mysql.com/mysql/189592

Depending on the SQL standard you are using the type can be MONEY, DECIMAL or NUMBER.


Need Your Help

How to disable keyboard on a UITextView?

objective-c ios ipad uitextview

I have used a Text view in my app for iPad on xib. I wrote some text on it. Now while the app is running and the user is reading that text, if he accidentally touches the screen a keyboard appear. ...

Algorithm and Implementation of Microflow Engine

java algorithm graph graph-theory bpm

I am working on microflow engine (backend) which is a process flow to be executed in runtime.