I'm currently investigating a bug in our system which is related to rounding errors. I just discovered that Math.floor() produces different results when using an operation as argument - e.g.: Math.floor(1681); // produces 1681 Math.floor(16.81 * 100) // produces 1680 Math.floor(16.811 * 100) // produces 1681  Can anyone explain why? This is hurting my brain.
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?
25130
Of course most languages have library functions for this, but suppose I want to do it myself.  Suppose that the float is given like in a C or Java program (except for the 'f' or 'd' suffix), for example "4.2e1", ".42e2" or simply "42". In general, we have the "integer part" before the decimal point, the "fractional part" after the decimal point, and the "exponent". All three are integers.  It is easy to find and process the individual digits, but how do you compose them into a value of type float or double without losing precision?  I'm thinking of multiplying the integer part with 10^n, where n is the number of digits in the fractional part, and then adding the fractional part to the integer part and subtracting n from the exponent. This effectively turns 4.2e1 into 42e0, for example. Then I could use the pow function to compute 10^exponent and multiply the result with the new integer part. The question is, does this method guarantee maximum precision throughout?  Any thoughts on this?
25826
How do I get whole and fractional parts from double in JSP/Java ? If the value is 3.25 then I want to get fractional =.25, whole = 3  How can we do this in Java?
26607
Is the concept of even/odd numbers applicable to decimal numbers? For e.g. - 4.222 is a even number?
4461
This prints 83  System.out.println(0123)   However this prints 123  System.out.println(123)   Why does it work that way?
80880
My code:  a = '2.3'   I wanted to display a as a floating point value.  Since a is a string, I tried:  float(a)   The result I got was :  2.2999999999999998   I want a solution for this problem. Please, kindly help me.  I was following .
2140
What I would like is a method to convert a double to a string which rounds using the half-up method - i.e. if the decimal to be rounded is 5, it always rounds up to the next number. This is the standard method of rounding most people expect in most situations.  I also would like only significant digits to be displayed - i.e. there should not be any trailing zeroes.  I know one method of doing this is to use the String.format method:  String.format("%.5g%n", 0.912385);   returns:  0.91239   which is great, however it always displays numbers with 5 decimal places even if they are not significant:   String.format("%.5g%n", 0.912300);   returns:  0.91230   Another method is to use the DecimalFormatter:  DecimalFormat df = new DecimalFormat("#.#####"); df.format(0.912385);   returns:  0.91238   However as you can see this uses half-even rounding. That is it will round down if the previous digit is even. What I'd like is this:  0.912385 -&gt; 0.91239 0.912300 -&gt; 0.9123   What is the best way to achieve this in Java?
112232
If percentage points can equal decimal points, then $1.25$ should equal $125$% when multiplying $1.25$ by any number.  Therefore $125$% of $0.75$ should equal $1$ if $0.75$ is also $75$% of $1$.   Am I missing something super obvious here or what?!  Please help. Thank you!
95377
Firstly I do not want to round my numbers, I am using base 10 figures so excel should have no bother doing simple add and subtract.  A|  665.110000000000000000000000000000 B|  4.990000000000000000000000000000 C|  =a1+b1 D|  670.790000000000000000000000000000 E|  1,335.890000000000000000000000000000 F|  =e1-(c1+d1)   I should get -5 however F1  returns   -4.999999999999770000000000000000   It is a financial document therefore I want to avoid rounding, more to the point. Why should I need to? I've put cell formatting to Currency with 2 decimal placed and I will get the correct display value but for all calculations I will still get -4.9999...7 which leads to further errors with conditional formatting etc.
67106
Is there a function to round a float in C or do I need to write my own?       float conver = 45.592346543;   I would like to round the actual value to one decimal place, conver = 45.6.
44849
Does anyone know why, using SQLServer 2005  SELECT CONVERT(DECIMAL(30,15),146804871.212533)/CONVERT(DECIMAL (38,9),12499999.9999)   gives me 11.74438969709659,  but when I increase the decimal places on the denominator to 15, I get a less accurate answer:  SELECT CONVERT(DECIMAL(30,15),146804871.212533)/CONVERT(DECIMAL (38,15),12499999.9999)   give me 11.74438969
120519
I realize the title of my question will probably cause the raising of some eyebrows, so let me explain. Not sure whether to file this under "math" or "philosophy". This also might be able to be explained away due to some possible misconceptions I have about irrational/transcendental numbers, so please correct me where I'm wrong, since I'm quite certain I am...but this is nagging me, so here it is:  Ok, so imagine a non-repeating decimal with an infinite number of digits in it. The numbers are random, but for the sake of argument, let's say the number starts with "0.2368210236..." and continues from there.  So I look at the first decimal digit - 2 - and think to myself "in the rest of this decimal, there are an infinite number of times that '2' shows up."  So I look at the first TWO decimal digits - 23 - and again, think to myself "due to the randomness and infinity of this decimal, there is statistically a 100% certainty that the numbers "23" show up, in that order, somewhere in the rest of this decimal.  Continuing this line of thought, I reach the conclusion that if I choose ANY number of digits (variable: x) that start off this infinite decimal number, then a) there is statistically a 100% certainty that particular sequence shows up somewhere else in the decimal, and b) that it shows up an infinite number of times.  If such is the case, then what happens as x approaches infinity? Would that not mean that, given enough length in the decimal, there would eventually come a point where the decimal starts repeating itself, ad infinitum? Would that not mean that what was originally thought of as an irrational number is actually rational? Would this line of thinking not apply to ALL irrational numbers?  I guess what I'm asking is this: could it be that there ARE no irrational numbers, just rational numbers whose scope and vastness outstrip our ability to see their rationality?  Alright, mathphiles; have at me!
117815
I have a table with a smallint column that contains percentages as whole numbers (i.e., 50, 75, 85, etc.)  When I divide this column by 100, as in  SELECT MY_COLUMN/100 AS PCT_AS_FRACTION FROM MY_TABLE   the result is rounded to the nearest whole number. For example, for a row that contains the number "50", I get zero as my result.  I can duplicate this with a simple statement:  SELECT 50 / 100 AS TEST_VALUE   Why is that, and how can I get more precision in my result?
8712
I read recently that you can find the number of digits in a number through the formula $\lfloor \log_{10} n \rfloor +1$ What's the logic behind this rather what's the proof?
72082
I have tried this on my Windows 7 calculator with $\sqrt9 -3 $ it too gives some weird answer- ie$1.1546388020691628168216106791278e-37$. And so for any $n$(positive) $\sqrt n^2-n= wierd_ .answer$ Why does this happen?
17258
What are the differences in mathematical notation around the world? I know that in some other countries they write 1,2 meaning 1.2, but what else can be confusing in an academic environment (when people are doing math on a board or on paper).
2201
I want a to be rounded to 13.95.  &gt;&gt;&gt; a 13.949999999999999 &gt;&gt;&gt; round(a, 2) 13.949999999999999   The  function does not work the way I expected.