如何在 sybase 数据库中截断实数、货币或小数值

How to truncate real, Money or decimal values in sybase database

我有一个名为的数据库函数:
dbo.cf_unpaid_interest_to_date

CREATE FUNCTION dbo.cf_unpaid_interest_to_date(@payment_plan guid_no_default)
returns REAL
AS
BEGIN
declare @runningdate datetime
declare @unpaidInterest REAL
declare @docAmt REAL
declare @type int
set @docAmt = 0
set @unpaidInterest = 0
 declare subread cursor
    for
        select tran_type, doc_amt, datestamp from cf_debtor_transaction 
        where payment_plan_guid = @payment_plan and tran_type in (4243,4743, 4751, 4251, 4423,4123,4112,4612) 
        and datestamp >= (select min(datestamp) from cf_debtor_transaction where payment_plan_guid = @payment_plan and tran_type = 4243) order by datestamp
open subread 

fetch subread into 
        @type, 
        @docAmt, 
        @runningdate
        while (@@sqlstatus=0)
     begin
      set @unpaidInterest = @unpaidInterest + @docAmt
      if(@unpaidInterest <= 0) set @unpaidInterest = 0 
      fetch subread into @type, @docAmt, @runningdate
     end
     return @unpaidInterest
end

我运行以下:

select func_cf_initiation_fee_not_yet_due, func_cf_unpaid_interest,func_cf_payment_plan_balance,installment, 
* from view_cf_payment_plan where account_guid ='0291507300';

我得到:13.639999

我希望值是:13.6300 而不是 13.639999

我试了 floor 但没用。

这可能会有所帮助...

SELECT ROUND(13.639999,2)
SELECT 13.639999 - ( 13.639999 % .01 )
SELECT "TRUNCATE"( 13.639999, 2)
SELECT TRUNCNUM( 13.639999, 2 )

如果您想要固定的小数位数,请使用 DECIMAL(precision, scale) 数据类型而不是 REAL。使用 REAL 时,您一定会出现舍入误差。