Why does MOD(11.2,2) give 1,2 and not 0?

Asked

Viewed 274 times

0

I need to take the rest of a division in ORACLE and I am using MOD that works very well with integers but when using decimal numbers it is a problem. Ex : MOD(11,2) = 1 ok MOD(11.2,2) = 1.2 Wrong is right in my understanding 0 because 11.2/2 = exact 5.6

Any help will be welcome

thank you

  • What is the database manager? (Oracle Database, SQL Server, mariaDB etc.)

  • Good morning Amigo Oracle 10g

1 answer

1

The result you expected MOD(11.2,2) = 0 is incorrect because the result of the split will always be an integer already the rest of the division may or may not be an integer then the correct result is 1.2 as 10 is divided by 2 which results in the integer 5.

If we were to follow its logic, any existing number would result in 0, since we can always divide by 2 if it is accepted as a result of the division a real number (type divide 3 mod 2, will give 1.5 and the rest = 0 what is wrong).

  • Hi friend, thanks for responding

  • Hi friend, thank you for answering But imagine 11.3 / 2 with only 1 decimal place Would give 5.6 and 0.01 This is the account I need, so I did in the same hand The scenario is the following : is a kind of apportionment between 2 or more beneficiaries of a certain amount and was giving error For example 238,93 divided by 2 benefits : R $ 119,46 for the first and the rest of this apportionment (R $ 0,01) would go to the second R $ 119,47. To my amazement . select mod(238.93,2) from dual; results in 0.93

Browser other questions tagged

You are not signed in. Login or sign up in order to post.