Gf: Which way do you round 4.5 up or down?

Me: (int)4.5;

Gf: Ffs the proper way!

Me: Math.Round(4.5);

Gf: Fuck off.

  • 9
    Except (int)foo is equivalent to floor(foo), so it would round 4.7 down to 4.
    Typically 4.5 would be rounded up by a round(foo) function, but (as I just found out) it seems that C# rounds it down...?!
  • 1
    @alyx It was a lazy response as my gf doesnt know anything about coding (I was hoping she would say "so I round down?") But she just said do it properly so I did. She is still confused.
  • 0
    Actually, scratch that, casts and floors are only equivalent for positive numbers. For negative numbers, floor rounds down while a cast rounds up.
  • 2
    Casts get rid of the floating point. They do technically round it to a full number, but the point is that it doesn't try to round up or down, just leave the number before the decimal point @alyx
  • 0
    @BartBB that's a much better way of looking at it. Thanks!
  • 2
    @alyx More specifically, it's called truncation.
  • 1
    Was looking for that word, but couldn't remember it, so I explained it instead xD @BearishMushroom
  • 0
    And don't forget Banker's Rounding!
  • 0
    Round halves towards the even number ;)
  • 1
    @LucaScorpion I didn't believe you. So I tested it. And oh my god the last 9 years of my life are a lie D:

    wtf, C#?!
  • 1
    @alyx There's actually a good reason for it. From wikipedia: "This method treats positive and negative values symmetrically, and is therefore free of sign bias."
  • 1
    @LucaScorpion Came to tell the good people of devrant my story of being an asshole. Got my mind blown instead lol. Ty for the trivia.
Add Comment