Javascript says 0.7-0.2 is equal to 0.49999999999999994.   The case is the following:  var change = 0.7 - 0.2;  switch (change) {     if (change.toFixed(2) &gt;= 1) {         ...     }     else if (change.toFixed(2) &gt;= 0.50) {         ...     }     else if (change.toFixed(2) &gt;= 0.20) {         ...     }     ... }   By using .toFixed() method, the problem is solved but is there another way, instead of using .toFixed() n-times;
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?
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?
99240
I write financial applications where I constantly battle the decision to use a double vs using a decimal.  All of my math works on numbers with no more than 5 decimal places and are not larger than ~100,000. I have a feeling that all of these can be represented as doubles anyways without rounding error, but have never been sure.  I would go ahead and make the switch from decimals to doubles for the obvious speed advantage, except that at the end of the day, I still use the ToString method to transmit prices to exchanges, and need to make sure it always outputs the number I expect. (89.99 instead of 89.99000000001)  Questions:   Is the speed advantage really as large as naive tests suggest? (~100 times) Is there a way to guarantee the output from ToString to be what I want? Is this assured by the fact that my number is always representable?   UPDATE: I have to process ~ 10 billion price updates before my app can run, and I have implemented with decimal right now for the obvious protective reasons, but it takes ~3 hours just to turn on, doubles would dramatically reduce my turn on time. Is there a safe way to do it with doubles?
80556
What's going on?! Subtraction works fine until I get to 0.1 - 0.1. I'm in visual c# 2008 using the nonoba.com API.  Console.WriteLine("hit! " + Users[targetNum].character.health + " : " + player.character.profile.attackPower);  Users[targetNum].character.health -= player.character.profile.attackPower;  Console.WriteLine("health! " + Users[targetNum].character.health);   output:  hit! 0.1 : 0.1 health! 1.490116E-08   Thanks all - I might use the decimal type, as I'm normally adding/subtracting nice "round" numbers. For now I'll just go with:  if (Users[targetNum].character.health &lt;= 0.00001)   By the way I knew this wasn't really going to be a "bug" in c# - I thought it would either by a bug in my code or some lack of understanding, which it was.  Having read all the recommended reading, I'm going to conclude that my folly was due to normally using the ActionScript Number type, which maybe has a decimal rather than binary floating point - anyway, it would never give this output.
2827
What's the cleanest, most effective way to validate decimal numbers in JavaScript?  Bonus points for:   Clarity. Solution should be clean and simple. Cross-platform.   Test cases:  01. IsNumeric('-1')      =&gt; true 02. IsNumeric('-1.5')    =&gt; true 03. IsNumeric('0')       =&gt; true 04. IsNumeric('0.42')    =&gt; true 05. IsNumeric('.42')     =&gt; true 06. IsNumeric('99,999')  =&gt; false 07. IsNumeric('0x89f')   =&gt; false 08. IsNumeric('#abcdef') =&gt; false 09. IsNumeric('1.2.3')   =&gt; false 10. IsNumeric('')        =&gt; false 11. IsNumeric('blah')    =&gt; false
15793
Let's say we have 0.33, we need to output 1/3.  If we have 0.4, we need to output 2/5.  The idea is to make it human-readable to make the user understand "x parts out of y" as a better way of understanding data.  I know that percentages is a good substitute but I was wondering if there was a simple way to do this?
60259
What is the difference between decimal, float and double in .NET?  When would someone use one of these?
5691
Is there a better way of getting this result? This function fails if num has more digits than digits, and I feel like it should be in the library somewhere (like Integer.toString(x,"%3d") or something)  static String intToString(int num, int digits) {     StringBuffer s = new StringBuffer(digits);     int zeroes = digits - (int) (Math.log(num) / Math.log(10)) - 1;      for (int i = 0; i &lt; zeroes; i++) {         s.append(0);     }     return s.append(num).toString(); }
76223
\documentclass{minimal} \usepackage{tikz} \begin{document} \pgfmathparse{random(-5,5)} \pgfmathresult \end{document}   Works, but I have a .0.0 that not supposed to be here.
26607
Is the concept of even/odd numbers applicable to decimal numbers? For e.g. - 4.222 is a even number?
43487
I have a double value f and would like a way to nudge it very slightly larger (or smaller) to get a new value that will be as close as possible to the original but still strictly greater than (or less than) the original.  It doesn't have to be close down to the last bit—it's more important that whatever change I make is guaranteed to produce a different value and not round back to the original.
82626
Suppose,I have a number 1256. I want (1256 % 11)! That is 2 . But, here, if i try in this way,  ( (125 % 11 ) * 10 + 6 ) % 11 = 2. That is exactly the same answer 2 as above.  I am confused , how This two process gives the similar answer ??? Even if , I try this method for any number n,m  to find (n mod m) . How this works ?? Can anybody explain ?
27648
double r = 11.631; double theta = 21.4;   In the debugger, these are shown as 11.631000000000000 and 21.399999618530273.  How can I avoid this?
3536
Possible Duplicate:          I want to truncate the decimals like below  i.e.   2.22939393 -> 2.229 2.22977777 -> 2.229
117305
I have a textbox in Javascript. When I enter '0000.00' in the textbox, I want to know how to convert that to only having one leading zero, such as '0.00'.
90637
Excel converting value 0503E000 to 5.03E+02 in any cell automatically in CSV I tried to convert it to text number and general but after i save it and reopen it again it goes back to 5.03E+02  How do I stop this from happening?
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 . . .