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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:56:40+00:00 2026-05-17T00:56:40+00:00

double a = 18.565 return Math.Round(a,2) ..returns 18.57. For every other number I tried

  • 0
double a = 18.565
return Math.Round(a,2)

..returns 18.57.
For every other number I tried banker’s rounding worked as expected, for example Math.Round(2.565,2) returned 2.56.

Any clue why and when that happens?
Is it error or am I missing something about banker’s rounding?

Thanks..

  • 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-17T00:56:42+00:00Added an answer on May 17, 2026 at 12:56 am

    As Matthew said, 18.565 can’t be accurately represented. The actual value used is 18.565000000000001278976924368180334568023681640625 (found using DoubleConverter), which is clearly beyond half-way. Now I’ve a sneaking feeling that sometimes Math.Round will consider a value which is actually beyond the half-way point, but which is as close to the half-way point as can be accurately represented, as being exactly at that point. However, I haven’t seen any documentation describing the situations in which that’s applied, and clearly it’s not happening in this case. I wouldn’t want to rely on it.

    Even the rounded value isn’t exactly 18.57 of course. It’s actually 18.57000000000000028421709430404007434844970703125.

    Fundamentally, if you really, really care about representing decimal values accurately, you should be using decimal. That’s not just in terms of Math.Round – it goes to every aspect of handling floating point values.

    That does give the right value for Math.Round, of course:

    decimal m = 18.565m;
    Console.WriteLine(Math.Round(m, 2)); // Prints 18.56
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If you return a double or float from your MBean jconsole seems to round
Why is there only Math.floor(double)? I have a float and I want to round
I want to double buffer a custom control which contains buttons. I have tried
double deg=90; double two= 2* System.Math.PI; double rad=(two)*(deg/360); the original value when calculating manually
I have double number in a format like 34.123456789 . How can I change
int main() { double i=4; printf(%d,i); return 0; } Can anybody tell me why
double Matrix::operator()(unsigned int a, unsigned int b) { return m[a*rows+b]; } I have the
private double _value; public object Value { get { return _value; } } I
Every time I double-click on an XML file, a spreadsheet thing opens. I find
double radius = 5; double area = Math.PI * Math.pow(radius, 2); // System.out.println(area); BigDecimal

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.