List<decimal> numlist = new List<decimal>(); numlist.Add(50.2m); numlist.Add(40.6m); numlist.Add(9.0m); decimal diff = 100.0m - numlist.Sum(); //This is set because the value should be only 1 decimal place int update = Convert.ToInt32(diff / .1m); if (update > 0) { for (int x = 0; x < update; x++) { numlist[x % numlist.Count()]...

In regards to your answer to yourself, you don't want to convert an object of type A to type B, operate on it, and then convert it back to type A. Not if you can do anything else. The following does what you want it to do: public double hypotenuse()...

What you want to do is to round to the closest 1/20th. So multiply the number by 20, round it, and divide by 20: n = Math.Round(n * 20) / 20 ...

I would test the distance with the standard rounding, then adjust and round again : for (String string : new String[] {"1.1245", "1.1244", "1.1235", "1.1249", "1.1299"}) { BigDecimal a = new BigDecimal(string); if (a.setScale(2, BigDecimal.ROUND_HALF_UP).subtract(a).compareTo(new BigDecimal("-0.0044")) < 0) { System.out.println(string + ":" + a.add(new BigDecimal("0.001")).setScale(2, BigDecimal.ROUND_HALF_UP)); } else { System.out.println(string...

c#,excel,rounding,rounding-error,number-rounding

First: The problem is hard. Because 4.53/2 = 2.265. This rounds to 2.27. However the tiniest rounding error in the calculation resulting in a smaller result (2.264999999....) will lead to a rounding to 2.26. This is what is happening here. To solve this problem you need to have a floating...

java,floating-point,number-rounding

One way to do this is to convert the price to cents, divide by 5, round to, multiply by 5 again and convert back to dollars: double rounded = Math.round(num * 100.0 / 5.0) * 5.0 / 100.0; ...

javascript,variables,number-rounding

As I know there is no way of doing that in core Javascript. You may have to write a on load function or some times there may be libraries to do that. But you will have to find hard for that.

python,logic,rounding,number-rounding

This is a weird restriction, but you could do this: x = str(x) dec_index = x.find('.') tenth_index = dec_index + 1 tenth_place = x[tenth_index] # will be a string of length 1 should_round_up = 5 + tenth_place.find('5') + tenth_place.find('6') + tenth_place.find('7') + tenth_place.find('8') + tenth_place.find('9') print int(x[0:dec_index]) + should_round_up What...

It is useful when you are performing multiple rounding operations and want the cumulative result to be a true average, and not skewed up or down, as it would be with HALF_UP or HALF_DOWN. Specifically, it is useful for statistical analysis (you don't want the results polluted by a non-random...

php,floating-point,decimal-point,number-rounding

You can set this parameters at run-time. 16 digits is usually the maximum value on most platforms, larger values giving only meaningless or "fictional" digits: ini_set("precision", "16"); See Changing precision level floating-point variables...

java,java-8,rounding,number-rounding

Seems that it's intended change. The JDK 1.7 behavior was incorrect. The problem is that you simply cannot represent the number 10.55555 using the double type. It stores the data in IEEE binary format, so when you assign the decimal 10.55555 number to the double variable, you actually get the...