如何截断系统间缓存中的除法结果?
How to truncate the result of a division in intersystems cache?
我想得到截断的整数。
例如做这个除法:5/3,
我希望结果为 1.
简单的方法是使用 $piece
write $piece(5/3,".",1)
1
或获取小数点分隔符
set decimalSeparator=##class(%SYS.NLS.Format).GetFormatItem("DecimalSeparator")
write $piece(5/3,decimalSeparator,1)
1
有一个 $fnumber
函数可以删除浮动部分,诀窍是在没有任何额外格式的情况下保留数字,为此您可以使用 ""
作为格式说明符。
write $fnumber(5/3,"",0)
2
[我现在看起来真的很傻,因为我没有阅读原始问题,但现在会回答 原始 问题]
如果你想在 COS 中做整数除法你需要使用 integer division \ operator
write 5
/ operator 永远做浮点数除法(除非你是Corba语言模式,别问是什么)
classmethod FLOOR(val As %Library.Numeric = "") as %Library.Integer
FLOOR is a numeric function that returns the largest integer less than or
equal to a given numeric expression
$SYSTEM.SQL.FLOOR(numeric-exp)
numeric-exp
A number whose floor is to be calculated.
我没有进行任何性能测试或其他任何事情,但这似乎正是您要找的。
我想得到截断的整数。
例如做这个除法:5/3, 我希望结果为 1.
简单的方法是使用 $piece
write $piece(5/3,".",1)
1
或获取小数点分隔符
set decimalSeparator=##class(%SYS.NLS.Format).GetFormatItem("DecimalSeparator")
write $piece(5/3,decimalSeparator,1)
1
有一个 $fnumber
函数可以删除浮动部分,诀窍是在没有任何额外格式的情况下保留数字,为此您可以使用 ""
作为格式说明符。
write $fnumber(5/3,"",0)
2
[我现在看起来真的很傻,因为我没有阅读原始问题,但现在会回答 原始 问题]
如果你想在 COS 中做整数除法你需要使用 integer division \ operator
write 5
/ operator 永远做浮点数除法(除非你是Corba语言模式,别问是什么)
classmethod FLOOR(val As %Library.Numeric = "") as %Library.Integer
FLOOR is a numeric function that returns the largest integer less than or equal to a given numeric expression
$SYSTEM.SQL.FLOOR(numeric-exp)
numeric-exp
A number whose floor is to be calculated.
我没有进行任何性能测试或其他任何事情,但这似乎正是您要找的。