i use python3, the code below:  import math print(round(1.755,2)) print(round(1.7555,3)) print("%.2f" % 1.755) print("%.3f" % 1.7555)   the result:  1.75 1.756 1.75 1.756   why, does round(1.755,2) = 1.76 ??
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?
44860
I am looking to format a number like 188518982.18 to £188,518,982.18 using Python.  How can I do this?
14483
As an example, the number 15, rounded to the nearest tens, rounds to 20. I understand it's arbitrary, as 10 and 20 are equidistant from 15, I just wonder if there's any discernible logic behind the convention of rounding up. Even something like, 'It just feels more natural', would probably satisfy me. Just had to ask :)
3011
Ok I hope I am mising something here as I really don't want this to be a bug.   The following piece of code returns 2. Per my understanding of the ceiling functionality, the result should be 3 because 7/3 is roughly 2.33333 and the ceiling should return 3.   Is this a bug or am I missing something? Thanks.   Integer pageNumber = (Integer) Math.ceil(7/3);   This returns 2 and not 3 as expected.   It works fine on other input. For example:  Integer pageNumber = (Integer) Math.ceil(8/5);   This returns 2 as expected.
38396
In a Tikz Figure, I'm doing some computation and want to print results as label of nodes. The problem is that I only need the integer part of the number to print.  I tried with round() function. It round the values correctly but they are printed with .0  \begin{tikzpicture}    \foreach \i in {1,2,3,4,5,6} {       \pgfmathparse{round(\i*100/3) }        \let\theIntINeed\pgfmathresult        \draw (\i,0) node {\theIntINeed};    }  \end{tikzpicture}  % Results: 33.0 67.0 100.0 133.0 167.0 200.0   Thank you in advance.
30616
I want to print the floating point number with exactly two significant digits in bash (maybe using a common tool like awk, bc, dc, perl etc.).  Examples:   76543 should be printed as 76000 0.0076543 should be printed as 0.0076   In both cases the significant digits are 7 and 6. I have read some answers for similar problems like:      but the answers focus on limiting the number of decimal places (eg. bc command with scale=2 or printf command with %.2f) instead of significant digits.  Is there an easy way to format the number with exactly 2 significant digits or do I have to write my own function?
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?
29904
If I have a double (234.004223), etc., I would like to round this to x significant digits in C#.  So far I can only find ways to round to x decimal places, but this simply removes the precision if there are any 0s in the number.  For example, 0.086 to one decimal place becomes 0.1, but I would like it to stay at 0.08.
28516
How do I format a number in Java? What are the &quot;Best Practices&quot;? Will I need to round a number before I format it?  32.302342342342343 =&gt; 32.30 .7323 =&gt; 0.73  etc.
23722
I've been wondering this for some time. As the title say, which is faster, the actual function or simply raising to the half power?  UPDATE  This is not a matter of premature optimization. This is simply a question of how the underlying code actually works. What is the theory of how Python code works?  I sent Guido van Rossum an email cause I really wanted to know the differences in these methods.  My email:     There are at least 3 ways to do a square root in Python: math.sqrt, the   '**' operator and pow(x,.5).  I'm just curious as to the differences in   the implementation of each of these.  When it comes to efficiency which   is better?   His response:     pow and ** are equivalent; math.sqrt doesn't work for complex numbers,   and links to the C  sqrt() function. As to which one is   faster, I have no idea...
99975
How do I get a random  instance? It appears that the random module only returns floats which are a pita to convert to Decimals.
12929
Could someone please tell me what I'm doing wrong with this code? It is just printing 'count' anyway.  I just want a very simple prime generator (nothing fancy).   import math  def main():     count = 3     one = 1     while one == 1:         for x in range(2, int(math.sqrt(count) + 1)):             if count % x == 0:                  continue             if count % x != 0:                 print count          count += 1
35731
I want to do this using the Math.Round function
24071
I'm trying to understand Python's approach to variable scope. In this example, why is f() able to alter the value of x, as perceived within main(), but not the value of n?  def f(n, x):     n = 2     x.append(4)     print('In f():', n, x)  def main():     n = 1     x = [0,1,2,3]     print('Before:', n, x)     f(n, x)     print('After: ', n, x)  main()   Output:  Before: 1 [0, 1, 2, 3] In f(): 2 [0, 1, 2, 3, 4] After:  1 [0, 1, 2, 3, 4]
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!
113353
I'm working with large numbers that I can't have rounded off.  Using Lua's standard math library, there seem to be no convenient way to preserve precision past some internal limit.  I also see there are several libraries that can be loaded to work with big numbers:      (might be identical to #2)  (but I can't find any source)   Further, there are  in C that could be called from Lua, if the bindings where established.  Have you had any experience with one or more of these libraries?