Delphi 中的 Trunc 方法
Trunc Method in Delphi
我正在将一些代码移植到 .Net,我意识到 Trunc 方法在 Delphi 中无法正常工作。它不考虑您是截断负值还是正值。它将论证视为绝对论证。
Delphi
Trunc(-163.78999) returns -163
.Net 实现
System.Math.Floor(-163.88888888888889) returns -164.
我可以模仿实现,但我想知道是否有人以前见过这个。
谢谢,
Delphi 的 Trunc
函数按设计执行。文档说(强调我的):
Truncates a real number to an integer.
In Delphi code, the Trunc function truncates a real-type value to an
integer-type value. X is a real-type expression. Trunc returns an
Int64 value that is the value of X rounded toward zero.
相当于 Delphi Trunc
的 .net 是 Math.Truncate
.
相当于.net System.Math.Floor
的Delphi是Floor
.
我正在将一些代码移植到 .Net,我意识到 Trunc 方法在 Delphi 中无法正常工作。它不考虑您是截断负值还是正值。它将论证视为绝对论证。
Delphi
Trunc(-163.78999) returns -163
.Net 实现
System.Math.Floor(-163.88888888888889) returns -164.
我可以模仿实现,但我想知道是否有人以前见过这个。
谢谢,
Delphi 的 Trunc
函数按设计执行。文档说(强调我的):
Truncates a real number to an integer.
In Delphi code, the Trunc function truncates a real-type value to an integer-type value. X is a real-type expression. Trunc returns an Int64 value that is the value of X rounded toward zero.
相当于 Delphi Trunc
的 .net 是 Math.Truncate
.
相当于.net System.Math.Floor
的Delphi是Floor
.