sql - 如何截去小数位而不向上舍入?

标签 sql sql-server tsql

假设我有以下十进制值:

4.584406

我需要一种简单快速的方法来截断小数而不向上舍入,因此输出将为 4.5

我正在使用 T-SQL (SQL Server 2005/2008)。

任何帮助将不胜感激。

最佳答案

使用round功能你可以试试这个

select round(4.584406, 1, 1)

输出将是

4.5

关键是第三个参数

ROUND ( numeric_expression , length [ ,function ] )

function

Is the type of operation to perform. function must be tinyint,

smallint, or int. When function is omitted or has a value of 0 (default), numeric_expression is rounded. When a value other than 0 is specified, numeric_expression is truncated.

关于sql - 如何截去小数位而不向上舍入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3895652/

相关文章:

sql-server - 强制特定存储过程在 30 秒后停止 : I do not want to reconfigure the timeout of the whole DB

sql - 有条件地仅更新 SQL Server 中的一条记录

tsql - 表变量上的 SQL SERVER 非聚集索引?

sql - 存储过程返回的别名列 [SQL Server 2008]

c# - 将 Visual Studio 2012 中的数据源从 SQLSRV 更改为 MySQL

sql - Hive 相对于同一表中的其他数组列对数组列进行排序

sql - 合并 3 个 Firebird 查询

sql-server - 如何从存储过程返回临时表

sql-server - 为什么 Intellisense 在 SQL Server Management Studio 2008 R2 中不起作用?

mysql - 无法通过socket '/tmp/mysql.sock'连接到本地MySQL服务器(2)