Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 903555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:54:03+00:00 2026-05-15T15:54:03+00:00

Short version: Why don’t I have to coerce 60, and int, into a double,

  • 0

Short version: Why don’t I have to coerce 60, and int, into a double, so that I can use division with another double if I DO care about the fractional part?

Long version: my boss called me out on a line of code. I tested it and it is working perfectly fine, but he thinks I have a bug waiting to happen.

int durationinseconds = 61;  // This is actually filled from a double.tryparse 
                             // from a string value out of an xml doc.
int durationinminutes = (int)Math.Ceiling((double)durationinseconds / 60);

My code is supposed to get the # of seconds from the XML doc, then figure out the # of minutes, always rounding up. 60 seconds = 1 minute, 61 seconds = 2 minutes, etc.

I’ve tested my code, but he INSISTS that the “/ 60” part should be “/ 60.0”.

I’ve tested my code with 0, 1, 2, 59, 60, 61, 119, 120, 121, 599, 600, 601, etc, and it always works out correctly.

Before I go defend myself to him, I mostly understand why he thinks that I need to coerce 60 to be a decimal, because he thinks that if I use an int value then a double / int will result in an integer value, effectively dropping the fractional part.

However, that is not happening here, and I can’t exactly explain why. So, that is my question: WHY don’t I have to use 60.0 when dividing a double if I want to use the fractional part?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T15:54:04+00:00Added an answer on May 15, 2026 at 3:54 pm

    Here are the relevant division operators:

    public static double operator /(double x, double y)
    public static int operator /(int x, int y)
    

    There is an implicit conversion from int to double, but not the other way round… so if you divide an int by an int, you’ll use the integer form… but if either operand is a double, it will use the double form.

    There’s no need to make both operands double – but your code would be at least shorter if you made the divisor operand a double instead of casting:

    int durationInMinutes = (int) Math.Ceiling(durationInSeconds / 60.0);
    

    Personally I find that easier to read… but it’s a personal choice.

    If you want to prove to your boss that it’s really doing floating point division, use iladsm or reflector (in IL mode) on your code – it will show an ldc.r8 instruction for the constant, which means a double value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Short version: How do I initialize and use DirectInput if I have no access
Short version: In trying to deal with a legacy database in Ruby-on-Rails, I've come
Short version: The default inspect method for a class displays the object's address.* How
Short Version : I'm using a 64bit dll (system.data.sqlite) in an Asp.net MVC app
Short Version of the question: I will put a quad. I know the width
In short, I've implemented a class that derives from SynchronizationContext to make it easy
I have started using WPF a short while back, and I'm in the progress
I have a console app, and a class library. I'm making changes to the
Greetings all, This has confused me ever since I first started coding in C#.
I was looking at a very slow SQL query (originating from a Java app

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.