javascript,floating-point,rounding,floor

function formatNumber(x) { // convert it to a string var s = "" + x; // if x is integer, the point is missing, so add it if (s.indexOf(".") == -1) { s += "."; } // make sure if we have at least 2 decimals s += "00";...

Yes, for negative numbers, this works in the opposite way. Example (using Mono's C# interactive shell csharp): csharp> Math.Floor(-12.0d) -12 csharp> Math.Floor(-12.5d) -13 csharp> (int) -12.5 -12 (same for both Java/C#) and I guess most languages anyway. Casting a floating-point number to an integer, is performed by throwing away the...

Take a look at this 0.30000000000000004.com Your language isn't broken, it's doing floating point math. Computers can only natively store integers, so they need some way of representing decimal numbers. This representation comes with some degree of inaccuracy. That's why, more often than not, .1 + .2 != .3. ...

excel,if-statement,excel-formula,floor,ceiling

You can use MROUND instead: =MROUND(A1,5) It rounds to the nearest 5. Anything including and above 277.5 will be rounded to 280, and anything below that will be rounded to 275. If you still want to use IF, then I would pick MOD: =IF(MOD(A1,5)>2.5, CEILING(A1,5), FLOOR(A1,5)) So, if the remainder...

haskell,floating-point,infinity,floor

The first question is perhaps not so important, so I'll try to answer the second question first. Once you have a number, if you know that it came from floor x, you can't know whether x was the valid representation of 2^1024 or if it was infinity. You can probably...

java,recursion,brute-force,divide-and-conquer,floor

You are trying to solve an integer equation: floor(n/7)*1+floor(n/8)*1+floor(n/10)*2 = 19 You can remove the floor function and solve for n and get a lower bound and upper bound, then search between these two bounds. Solving the following equation: (n/7)*1+(n/8)*1+(n/10)*2 = 19 n=19/(1/7+1/8+2/10) Having found n, which range of value...

javascript,python,bit-manipulation,rounding,floor

just cast the float to an int int(2.667) it will always floor/truncate the float once the float is non negative if you have negative numbers you do want to floor not just truncate use math.floor . In [7]: int(2.667 ) Out[7]: 2 In [22]: from math import floor In [23]:...

algorithm,search,floor,ceiling

There's no difference in complexity. Both variants are log(n). Depending on the rest of your implementation, you may get a different result if your array looks for instance like 0 1 1 1 1 2 and looking for the index of a 1....

The simplest solution to the decision tree problem you mention in comments would be to think in terms of the range of doubles that should go to a particular branch of the tree, rather than a single double. However, here is an attempt at the conversion function you asked for:...

The functions ceil() and floor() will return different numbers than what you get by using up = (int)(test + 1); down = (int)test; when you have a negative number. If you have: float test = -1.3548; up = (int)test; // ceil() down = (int)(test-1); // floor() Even the last statement...

Your array is declared as: solvent_p solvent[4000]; but you have this loop: for(i=0;i<=9999;i++) with this function call inside: printf("1 :%d \t %f \t %f \n",j,solvent[j].rx,solvent[i].ry); which means you are accessing out-of-bounds array elements. EDIT: OP test case has been edited to fix the out-of-bound accesses. My second suggestion is to...

It will be always TRUE only in this scenario When the value stored in ix with 'int' function, it will ignore the float values and just consider the whole number before the decimal point. In case of Floor, it will convert to the nearest lower whole number. The only difference...