Why modulo runs fine with decimal but not with float/real MSDN states about it "must be a valid expression of any one of the data types in the integer and monetary data type categories, or the numeric data type." why not floating values, because it is an approximate value ??
--Runs fine
declare @pri decimal
set @pri = 3.25
select @pri%2
Result 1
--Gives an error 402
declare @pri float
set @pri = 3.25
select @pri%2
Msg 402, Level 16, State 1, Line 3 The data types float and numeric are incompatible in the modulo operator.
If your question about the documentation?
MSDN documentation
dividend must be a valid expression of any one of the data types in the integer and monetary data type categories, or the numeric data type.
It says integer, monetary (money, smallmoney) and numeric
So, decimal is not supported. The documentation says "numeric is functionally same as decimal" but may be it has different meaning in some context like this one.
I guess, float is treated as numeric datatype where as decimal is not
Read the data types. It has information on monetary data types. (money, smallmoney)
Update:
Here is the catagory wise data type list. You can follow the links to numeric and money to find what datatypes falls in it
What are you trying to achieve here? Modulo is an integer operator, it computes the remainder of the integer division.
If you expect 1.25 as result convert pri
to an integer, do the division (this will give you 1) multiply by 2 and subtract the result from pri
(3.25 - ((3/2) *2).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With