How to divide without a remainder (not round, but just “cut off” the remainder after the comma) in C #?
UPD
I’m trying to write a simple timer for Unity 🙂
-
The user enters hours, minutes and seconds, (each has its own
variable int). -
This is then converted to total seconds and assigned to float.
-
One is subtracted every second using Time.deltaTime (the latter produces a float, so it was necessary to store seconds in a float).
-
Then the seconds are recalculated again into hours, minutes and seconds and assigned to the corresponding variables.
This is where the problem appears: You need to either convert seconds from float to int, or initially all variables should be made float but “cut off” the decimal places.
Answer 1, authority 100%
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.