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

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) 

https://stackoverflow.com/questions/3104948/

相关文章:

python - 何时使用 * 和 ** 作为 python 函数中的函数参数

asp.net-mvc - 将 "domain services"放在域模型项目中的位置

php - [function.fopen] : failed to open stream: HT

php - 检查字符串是否为哈希

functional-programming - 与实数的模式匹配(标准 ML)

ruby-on-rails - 如果给定的工厂存在,我可以问 Factory Girl 吗?

c# - 无法对 SQL Server Express 2008 使用 SQL Server 身份验

php - 阈值在php代码中是什么意思

php - 加入 str_replace 与 strtolower

python - lxml 的 iterparse 中有多个标签名称?