Linked Questions
4,751 questions linked to/from Is floating point math broken?
94
votes
8
answers
58k
views
PHP - Floating Number Precision [duplicate]
$a = '35';
$b = '-34.99';
echo ($a + $b);
Results in 0.009999999999998
What is up with that? I wondered why my program kept reporting odd results.
Why doesn't PHP return the expected 0.01?
56
votes
6
answers
24k
views
Is double Multiplication Broken in .NET? [duplicate]
If I execute the following expression in C#:
double i = 10*0.69;
i is: 6.8999999999999995. Why?
I understand numbers such as 1/3 can be hard to represent in binary as it has infinite recurring ...
96
votes
2
answers
146k
views
Float sum with javascript [duplicate]
Possible Duplicate:
Is JavaScript's Math broken?
I'm calculating the sum of several float values using javascript and... I've noticed a strange thing never seen before. Executing this code:
...
83
votes
4
answers
141k
views
JavaScript adding decimal numbers issue [duplicate]
So I am making a script that adds two numbers (decimal numbers) together, which I have encountered a problem.
http://jsfiddle.net/DerekL/esqnC/
I made the script, it turns out pretty good:
0.1 + 0....
80
votes
5
answers
69k
views
Why does adding two decimals in Javascript produce a wrong result? [duplicate]
Possible Duplicate:
Is JavaScript’s Math broken?
Why does JS screw up this simple math?
console.log(.1 + .2) // 0.3000000000000004
console.log(.3 + .6) // 0.8999999999999999
...
52
votes
3
answers
73k
views
Python modulo on floats [duplicate]
Can anyone explain how the modulo operator works in Python?
I cannot understand why 3.5 % 0.1 = 0.1.
36
votes
7
answers
35k
views
Floating point arithmetic not producing exact results [duplicate]
I need to do some floating point arithmetic in Java as shown in the code below:
public class TestMain {
private static Map<Integer, Double> ccc = new HashMap<Integer, Double>() {
...
12
votes
6
answers
30k
views
C++ How to avoid floating-point arithmetic error [duplicate]
I am writing a loop that increments with a float, but I have come across a floating-point arithmetic issue illustrated in the following example:
for(float value = -2.0; value <= 2.0; value += 0.2)
...
29
votes
2
answers
47k
views
Python rounding error with float numbers [duplicate]
I don't know if this is an obvious bug, but while running a Python script for varying the parameters of a simulation, I realized the results with delta = 0.29 and delta = 0.58 were missing. On ...
25
votes
3
answers
15k
views
Why does Math.cos(90 * Math.PI/180) yield 6.123031769111... and not zero? [duplicate]
I convert degrees to radians (degrees * Math.PI/180) but why does the following:
Math.cos(90 * Math.PI/180)
yield 6.123031769111... and not zero?
I'm trying to perform 2D rotations uses matrixes ...
5
votes
10
answers
2k
views
1.265 * 10000 = 126499.99999999999? [duplicate]
When I multiply 1.265 by 10000 , I get 126499.99999999999 when using Javascript.
Why is this so?
23
votes
6
answers
18k
views
Simple subtraction bug in Javascript [duplicate]
I was shocked to see such a basic subtraction bug in JS, I am sure most of you here would have experienced this issue, please help me with a work around here,
All I am doing is subtracting a number ...
21
votes
2
answers
4k
views
float/double Math.Round in C# [duplicate]
float ff = (float)31.15;
double dd = 31.15;
var frst = Math.Round(ff, 1, MidpointRounding.AwayFromZero);
var drst = Math.Round(dd, 1, MidpointRounding.AwayFromZero);
frst: 31.1
drst: 31.2
Can ...
17
votes
3
answers
41k
views
Why does the sum of 2 parseFloat variables give me an incorrect decimal number [duplicate]
If I have this little function:
<script type="text/javascript">
function printFloat(){
var myFloatNumber1 = document.getElementById('floatNumber1');
var myFloatNumber2 = document....
10
votes
4
answers
3k
views
Strange floating-point behaviour in a Java program [duplicate]
In my program I have one array with 25 double values 0.04
When I try to sum these values in a loop I get following results:
0.0 + 0.04 = 0.04
0.04 + 0.04 = 0.08
0.08 + 0.04 = 0.12
0.12 + 0.04 = 0.16
...