Home c# How to split without remainder in C #?

How to split without remainder in C #?

Author

Date

Category

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%

https://ideone.com/DTGGxw

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.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions