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

  • Home
  • SEARCH
  • 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 6382199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:29:31+00:00 2026-05-25T02:29:31+00:00

I have a problem with my client side script not calculating the same values

  • 0

I have a problem with my client side script not calculating the same values as my server side code:

For example:

var x = (2.85 * .1);
alert(x);

This gives a figure of 0.28500000000000003

However my server side code (C#) calculates a figures of 0.285 which when rounded to 2 decimal places gives 0.28

If I try and round 0.28500000000000003 to 2 decimal places I get 0.29.

How do I get my Javascript to create a figure that matches my server side code.

It looks like I have to go through 2 lots of rounding – firstly to remove the trailing 3, then the rounding to the required decimal places.

For example:

var x = 0.2850000000003;
x = parseFloat(x.toFixed(3))
x = x.toFixed(2)
alert(x);

Is this the best workaround?

(this is a re-wording of a question I opened and deleted earlier)

  • 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-25T02:29:32+00:00Added an answer on May 25, 2026 at 2:29 am

    .Net uses banker’s rounding. If a number is at the rounding midpoint e.g. 2.5 then the number is rounded to the closest even number, in this case 2. Rounding in this manner eliminates the bias introduced by rounding upwards.

    You can use bankers rounding in javascript using the snippet at http://snippets.dzone.com/posts/show/1305.

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

Sidebar

Related Questions

I have a problem. Client side code <html> <body onload=fun()> <script src=C:\cygwin\usr\local\lib\node\.npm\socket.io\0.6.16\package\support\socket.io-client\socket.io.js></script> <script> function
all. I'm having a bit of weird problem with client server program. I have
I have this little problem. My client wanted two distinct swf on a web
I have this jsp client that consumes a webservice. The problem with the client
i have a client side jquery script that logs the user off after 5
I have a class at server-side like this: public class Address { public Address(string
I have a problem with a client, who cannot log in to our system.
I have a problem with a specific java client library. Here is the situation:
I have a problem. The client is claiming that a prize signup form I
The problem: let's say I have two tables Client , and Product , in

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.