【问题标题】:How to truncate decimal in Microsoft SQL Server [duplicate]如何在 Microsoft SQL Server 中截断小数 [重复]
【发布时间】:2019-09-25 09:28:37
【问题描述】:

函数 TRUNCATE 在 MySQL 中有效,但在 Microsoft SQL Server 中出现错误:附近的语法不正确 ( 基本上我有折扣价清单。 (有些有很多小数) 我只想保留小数点后 2 而不四舍五入。 例如,从 110.975 到 110.97、10.259 到 10.25。我该怎么做呢?

SELECT TRUNCATE(110.975,2)

【问题讨论】:

    标签: sql sql-server truncate


    【解决方案1】:

    你可以这样使用round

    ROUND (110.975 , 2 , 1 )
    
    ROUND ( numeric_expression , length [ ,function ] )
    

    function 是要执行的操作类型。功能必须是 tinyint、smallint 或 int。当函数被省略或值为 0(默认),numeric_expression 是四舍五入的。当值不是 0 时 指定,numeric_expression 被截断。

    https://docs.microsoft.com/en-us/previous-versions/sql/sql-server-2005/ms175003(v=sql.90)?redirectedfrom=MSDN

    【讨论】:

      猜你喜欢
      • 2017-03-18
      • 2017-10-30
      • 1970-01-01
      • 1970-01-01
      • 2010-09-07
      • 2019-04-23
      • 2010-10-29
      • 1970-01-01
      • 2019-10-01
      相关资源
      最近更新 更多