I am porting some code to .Net and I realized that the Trunc method is not properly working in Delphi. It doesn't account whether you are truncating a negative or positive value. It treats the argument as absolute.
Delphi
Trunc(-163.78999) returns -163
.Net Implementation
System.Math.Floor(-163.88888888888889) returns -164.
I can mimic the implementation but I am wondering if anyone has seen this before.
Thanks,
Delphi's Trunc function performs as designed. The documentation says (emphasis mine):
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.
The .net equivalent to Delphi Trunc is Math.Truncate.
The Delphi equivalent to .net System.Math.Floor is Floor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With