While fixing an validation error preventing user from saving with the message      "You have 100%. You need to have 100%!"   I have ran into very interesting issue happening in both Firefox 34 and IE 11:  0.57+8.36+3.36+0.19    gives in Firefox and Chrome  12.479999999999999   And in IE  12.479999999999998   If no one wants to calculate, correct result would be 12.48  I will fix issue now by using Math.Round in reduce function to "correct" value on every step, but real question is, what is cause of this at the first look (of naive user) incorrect behavior?    Note that I have originally discovered issue by trying to sum an Array:  [ 0.57, 8.36, 3.36, 0.19, 39.29, 6.37, 17.24, 0.16, 2.07, 0.04, 22.36].sum() [ 0.57, 8.36, 3.36, 0.19, 39.29, 6.37, 17.24, 0.16, 2.07, 0.04, 22.36].reduce(function(item,item2){return item+item2})
27
Consider the following code:   0.1 + 0.2 == 0.3  -&gt;  false   0.1 + 0.2         -&gt;  0.30000000000000004   Why do these inaccuracies happen?
8965
According to the documentation, the  method uses a round-to-even algorithm which is not common for most applications. So I always end up writing a custom function to do the more natural round-half-up algorithm:  public static decimal RoundHalfUp(this decimal d, int decimals) {     if (decimals &lt; 0)     {         throw new ArgumentException("The decimals must be non-negative",              "decimals");     }      decimal multiplier = (decimal)Math.Pow(10, decimals);     decimal number = d * multiplier;      if (decimal.Truncate(number) &lt; number)     {         number += 0.5m;     }     return decimal.Round(number) / multiplier; }   Does anybody know the reason behind this framework design decision?  Is there any built-in implementation of the round-half-up algorithm into the framework? Or maybe some unmanaged Windows API?  It could be misleading for beginners that simply write decimal.Round(2.5m, 0) expecting 3 as a result but getting 2 instead.
70376
I wanted to see if folks were using decimal for financial applications instead of double.  I have seen lots of folks using double all over the place with unintended consequences . .  Do you see others making this mistake . . .
98068
function onlyNumeric() {        if (event.keyCode &lt; 48 || event.keyCode &gt; 57) {         event.returnValue = false;      }  }  onkeypress=onlyNumneric();   In IE, this code is working fine. However, in Mozilla Firefox, the event is an undefined error.
7653
public class doublePrecision {     public static void main(String[] args) {          double total = 0;         total += 5.6;         total += 5.8;         System.out.println(total);     } }   The above code prints:  11.399999999999   How would I get this to just print (or be able to use it as) 11.4?
5995
When displaying the value of a decimal currently with .ToString(), it's accurate to like 15 decimal places, and since I'm using it to represent dollars and cents, I only want the output to be 2 decimal places.   Do I use a variation of .ToString() for this?
60853
For context: This is a desktop application interacting with a service running on W7.  I'll try and leave all the technical details out of this, but here goes:  Part of my application has to send a large amount of data to the server which is then validated server side. Any errors found are sent back to the client to handle.  My 'problem' is that this large amount of data (in this case, a person) can have a lot of things 'wrong with it' which can be summarised into two main errors:   Required fields not being filled in. (Name not provided) Data being entered but still invalid due to a business rule (person is under the age of 18, phone number entered as ABC123, assessment was completed, but no completion date was entered, etc.)   Now even with all the client side validation I can put in, there still might be cases when a number of errors that aren't detected. (business rules, mostly) How should these errors be displayed to the client? I only see three real options here:   Displaying the server side errors into the UI somehow. I'd like to avoid this possible since I'm not 100% sure on how to code this without writing a mass of spaghetti code to determine which error is for which field. List one error at a time. When a user submits the data, show the first error that is returned and ignore all the others. When the user resubmits, shows the next one, and so on. I have a feeling this could annoy some people who will probably send me angry emails along the lines of 'Why don't you show me all the errors at once?!?!?' Show them all at once. I could have all the errors showing at once, but this is going to cause a few problems:   The dialog box should potentially be huge if they've somehow got 15 or so errors. No one is going to remember all 15 problems unless they screenshot the message or write them down. The API on Windows might not allow me to fit all message in one dialog leaving users to click through an unknown amount of dialogs.    How should I approach this?
89952
There are a  on this topic, but no simple and definitive answers.    Can someone please tell me how to permanently disable cell rounding on the .csv file which is created by script?  Basically, '377635637222436751' is being converted to '377635637222437000' automatically and that isn't really acceptable for my needs.  I've tried this: Tools->Options->Calc->Calculate "Precision as shown"   and this: Format > Cells > Numbers > Category > (scroll down for) Text. (but considering my script creates the .csv -- this option isn't very good since it must be done after the file is created)  And neither is working.  The number stays rounded -- even after formatting the column after the file is created.  Does anyone have any suggestions?
115153
I know you can't rely on equality between double or decimal type values normally, but I'm wondering if 0 is a special case.  While I can understand imprecisions between 0.00000000000001 and 0.00000000000002, 0 itself seems pretty hard to mess up since it's just nothing.  If you're imprecise on nothing, it's not nothing anymore.  But I don't know much about this topic so it's not for me to say.  double x = 0.0; return (x == 0.0) ? true : false;   Will that always return true?
45178
I was looking for this a while back for JavaScript, but I was wondering a general purpose one exists for all, or most languages.  For example for LaTeX I would put the following in a text box  $f_i^k+10=x$   and it spits out the better formatted version  %%% %% Insert comment describing function here %%% $ f_{i}^{k} + 10 = x $   I can't be the only person on the planet that does not wish to go through a massive .tex file and fix these tedious problems.
81932
I am using Adobe Illustrator CS6 to create small images (like icons) for my app so I need pixel precision.  How can I avoid X, Y, W and H properties to have decimals? Can I configure 0 decimals for this properties on my document?  If I use the textboxes with this properties it does right, it increases pixel by pixel, but when draggin with the mouse it uses up to 3 decimals.
32185
I'm trying to determine the best way to truncate or drop extra decimal places in SQL without rounding.  For example:  declare @value decimal(18,2)  set @value = 123.456   This will automatically round @value to be 123.46, which is good in most cases.  However, for this project, I don't need that.  Is there a simple way to truncate the decimals I don't need?  I know I can use the left() function and convert back to a decimal.  Are there any other ways?
87887
I need a simple floating point rounding function, thus:   double round(double);  round(0.1) = 0 round(-0.1) = 0 round(-0.9) = -1   I can find ceil() and floor() in the math.h - but not round().  Is it present in the standard C++ library under another name, or is it missing??
41282
Here's my code:  x = 1.0 y = 100000.0     print x/y   My quotient displays as 1.00000e-05.  Is there any way to suppress scientific notation and make it display as 0.00001? I'm going to use the result as a string.
96381
I've been trying to use decimal values as params for a field attribute but I get a compiler error.  I found this blog post  saying it wasn't possible in .NET to use then, does anybody know why they choose this or how can I use decimal params?
117193
Do we need to be careful when comparing a double value against zero?  if ( someAmount &lt;= 0){ ..... }
31758
The documentation for the  function states that you pass it a number, and the positions past the decimal to round. Thus it should do this:  n = 5.59 round(n, 1) # 5.6   But, in actuality, good old floating point weirdness creeps in and you get:  5.5999999999999996   For the purposes of UI, I need to display 5.6. I poked around the Internet and found some  that this is dependent on my implementation of Python. Unfortunately, this occurs on both my Windows dev machine and each Linux server I've tried. .  Short of creating my own round library, is there any way around this?