Truncate
ExamplesΒΆ
Returns a double
value or decimal
value to the whole number WITHOUT rounding.
Math.Truncate(number);
Example
1 2 3 4 5 | double test = -129.768009;
Console.WriteLine(Math.Truncate(test));
Console.WriteLine(Math.Truncate(59.22));
Console.WriteLine(test.GetType());
|
Console Output
-129
59
System.Double
Note that the value printed is the numbers that preceeded the decimal point.
Truncate does NOT round, only shortens.
While the output looks like an int
type, it is still a double
.