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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:28:43+00:00 2026-05-13T10:28:43+00:00

I know from reading this Stackoverflow question that the complier will look at your

  • 0

I know from reading this Stackoverflow question that the complier will look at your number, decide if the midpoint is an even or odd number and then return the even number. The example number was 2.5 which rounded to a 3. I’ve tried my own little experiments to see what happens, but I have yet to find any specifications about this, or even if it would be consistent between browsers.

Here’s an example JavaScript snippet using jQuery for the display:

$(document).ready(function() {
    $("#answer").html(showRounding());
});

function showRounding() {
    var answer = Math.round(2.5);
    return answer;
}

This returns a ‘3’.

What I would like to know is this: How close is the rounding in JavaScript to the the C# equivalent? The reason I’m doing this is because I would like to take a JavaScript method that uses Math.Round and rewrite the same method into C# and would like to know that I would be able to get the same results after rounding a number.

  • 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-13T10:28:43+00:00Added an answer on May 13, 2026 at 10:28 am

    Here’s the complete javascript specification for Math.round(x):

    15.8.2.15 round (x) Returns the Number value that is closest to x and is
    equal to a mathematical integer. If
    two integer Number values are equally
    close to x, then the result is the
    Number value that is closer to +∞. If
    x is already an integer, the result is
    x.

    • If x is NaN, the result is NaN.
    • If x is +0, the result is +0.
    • If x is −0, the result is −0.
    • If x is +∞, the result is +∞.
    • If x is −∞, the result is −∞.
    • If x is greater than 0 but less than
      0.5, the result is +0.
    • If x is less than 0 but greater than or equal to -0.5, the result
      is −0.

    NOTE 1 Math.round(3.5) returns 4, but
    Math.round(–3.5) returns –3.

    NOTE 2 The value of Math.round(x) is
    the same as the value of
    Math.floor(x+0.5), except when x is −0
    or is less than 0 but greater than or
    equal to -0.5; for these cases
    Math.round(x) returns −0, but
    Math.floor(x+0.5) returns +0.

    The C# Language Specification does not stipulate any particular rounding algorithm. The closest thing we have is the documentation for .NET’s Math.Round. From that, you can see that some of the javascript cases don’t apply (Math.Round only handles decimals and doubles, not infinity), and the method’s overloads give you a lot more control over the result – you can specify the number of fractional digits in the result and the midpoint rounding method. By default, Math.Round uses ‘banker’s rounding’ (to even).

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

Sidebar

Ask A Question

Stats

  • Questions 304k
  • Answers 304k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer As far as I know the DataContext.CreateDatabase method can only… May 13, 2026 at 8:48 pm
  • Editorial Team
    Editorial Team added an answer Have you tried using rspec-rails: http://github.com/rspec/rspec-rails That is the repository… May 13, 2026 at 8:48 pm
  • Editorial Team
    Editorial Team added an answer Case classes can be seen as plain and immutable data-holding… May 13, 2026 at 8:48 pm

Related Questions

According to this article from Herb Sutter, one should always pick Class Specializing over
Recently, I've got a dangerous idea into my head after reading this blog post.
I want to validate a set of credentials against the domain controller. e.g.: Username:
I have looked all of the place for this and I can't seem to
I'm very new to programming and I'm just starting to learn VBA with excel.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.