sql-server - 如何计算 SQL 中 float 的模数?

标签 sql-server tsql math

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 据类型时,这不起作用。下面列出了我们得出的答案,以供将来引用。

[1] http://msdn.microsoft.com/en-us/library/ms190279.aspx

最佳答案

转换为十进制/数字、取模并转换回?

CAST(CAST(TheInaccurateFloatValue AS decimal(38,19)) % ModuloValue AS float) 

关于sql-server - 如何计算 SQL 中 float 的模数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3104948/

相关文章:

algorithm - 字符串模素数的不同排列

javascript - 确定3个坐标之间的 Angular

sql-server - T-SQL 替代嵌套 CASE 以获得更好的性能?

sql-server - 为 asp.net MVC 应用程序更好地访问数据的路线图

sql - 使用 IF..ELSE IF 控制 T-SQL SP 中的流程 - 还有其他方法吗?

sql - 使用变量创建模式的脚本

sql - 从具有相同外键的所有其他记录都具有特定值的表中选择记录

python - 如何计算多变量方程的输出

SQL 父子树按深度和显示顺序排序

PHP + PDO : Bind null if param is empty