Microsoft SQL Server 中的取模函数仅适用于某些数据类型。
根据关于模数运算符的 MSDN 文章 [1],您通常会像这样使用模数...
dividend % divisor
dividend
Is the numeric expression to divide. 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.
divisor
Is the numeric expression by which to divide the dividend.
divisor must be any valid expression of any one of the data
types in the integer and monetary data type categories, or
the numeric data type.
但是,当股息是 float 据类型时,这不起作用。下面列出了我们得出的答案,以供将来引用。
最佳答案
转换为十进制/数字、取模并转换回?
CAST(CAST(TheInaccurateFloatValue AS decimal(38,19)) % ModuloValue AS float)
关于sql-server - 如何计算 SQL 中 float 的模数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3104948/