How to divide without remainder in C#?
How to divide without remainder (not round but just "cut off" the remainder after the decimal point) in C#?
UPD
I'm trying to write a simple timer for Unity :)
-
The user enters hours, minutes, and seconds, (each with its own int variable).
-
Then all this is converted to the total number of seconds and assigned to the float variable.
-
Each second is subtracted by a unit using Time. deltaTime (the last one outputs float, so it was necessary to store seconds in float).
-
After that, the seconds are again converted to hours, minutes, and seconds and assigned to the corresponding variables.
That's where the problem comes in: You either need to convert seconds from float to int, or initially make all variables float but "cut off" the decimal places.
1 answers
using System;
public class Test
{
public static void Main()
{
double x = 1e11;
Console.WriteLine((long)x / 60);
Console.WriteLine(Math.Floor(x / 60));
}
}
And in general, there is no point in using fractional numbers for time. Use whole seconds or milliseconds, like everywhere else.