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 8800059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:29:13+00:00 2026-06-14T00:29:13+00:00

Doing some calculations with doubles which then need to be cast to an int.

  • 0

Doing some calculations with doubles which then need to be cast to an int. So i have a quick question, when casting a double say 7.5 to an int, it will return 7.

Is this a product of rounding or just striping anything after the decimal point?

If it is a product of rounding, is it smart ie 0.1 to 0.5 it rounds down and 0.6 to 0.9 it rounds up?

Cheers

  • 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-06-14T00:29:14+00:00Added an answer on June 14, 2026 at 12:29 am

    It does not round, it just returns the integral part before the decimal point.

    Reference (thanks Rawling) Explicit Numeric Conversions Table:

    When you convert a double or float value to an integral type, this
    value is rounded towards zero to the nearest integral value.

    You can try simple issues like this by yourself by writing simple tests. The following test (using NUnit) will pass and therefore give an answer to your question:

    [Test]
    public void Cast_float_to_int_will_not_round_but_truncate
    {
        var x = 3.9f;
        Assert.That((int)x == 3); // <-- This will pass
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have C code doing some calculations (irrelevant to my question, I believe ).
I was doing some rounding calculations and happened upon a question. How can I
I am doing some shipping calculations. I need some help trying to figure this
in my C#-Silverlight-3-Application, I have created a class, that is doing some calculations that
I'm working on a for-fun-project that I will be doing some calculations with and
In my mxml file, I'm doing some calculations in the script tag, and binding
Doing some jquery animation. I have certain divs set up with an attribute of
I have an issue with some inheritance I'm doing. Basically, I have an abstract
I'm doing some calculations, and the results are being save in a file. I
I am having some weird issue here. I have a database table which has

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.