1

http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc38151.1540/doc/html/san1278453173757.html

Adaptive Server Enterprise 不支持函数 TRUNCATE 和 TRUNCNUM。

有谁知道在 ASE 中这样做的另一种方法?

谢谢

4

3 回答 3

2

我知道这些方法:

select Number = floor ( 455.443 )
select Number = cast ( 455.443 as int )
select Number = convert ( int, 455.443 )
select Number = 455.443 - ( 455.443 % 1 )
于 2013-08-28T23:09:41.827 回答
0

使用 Floor 功能怎么样?它基本上做同样的事情,并且在 ASE 中得到支持。

于 2013-05-24T15:33:45.170 回答
0

这是一个老问题,但几天前我这样做是为了模仿上面链接中描述的“truncnum”函数。

create function custom_truncnum(@numberToTruncate float, @decimalPlaces int)
returns float
AS
    declare @tenToTheXPower float;
    declare @leftSideOfDecimal float;
    declare @returnVal float;

    set @tenToTheXPower = power(10, ABS(@decimalPlaces);
    set @leftSideOfDecimal = FLOOR(@numberToTruncate);

    if (@decimalPlaces <= 0)
        set @returnVal = FLOOR(@numberToTruncate / @tenToTheXPower) * @tenToTheXPower;
    else
        set @returnVal = @leftSideOfDecimal + (FLOOR(@numberToTruncate - @leftSideOfDecimal) * @tenToTheXPower) / @tenToTheXPower);

    return @returnVal;
GO

现在您应该能够在 Sybase ASE 中执行此操作:

SELECT dbo.custom_truncnum(345.567, 2) 
    345.56

SELECT dbo.custom_truncnum(345.562, 2) 
    345.56

SELECT dbo.custom_truncnum(345.567, -1) 
    340

SELECT dbo.custom_truncnum(345.567, -2) 
    300

SELECT dbo.custom_truncnum(345.567, 0)  --This is the same as FLOOR(345.567)
    345
于 2015-03-13T03:15:43.193 回答