Tag Archives: rounding

Control a loop that uses floating-point values in C#

Sometimes you might need to use a floating-point variable that loop over a range of values. For example, you might want a value to step through the values 0.0 through 1.0 in increments of 0.1. The sequence of numbers would … Continue reading

Posted in calculations, mathematics, variables | Tagged , , , , , , , , , , , , , , | Leave a comment

Compare floating-point values safely in C#

The computer stores values, including floating-point values, in binary using 0s and 1s. That means it cannot store all possible decimal values exactly. Sometimes when you multiply or divide two floating-point values, the computer is unable to store the result … Continue reading

Posted in calculations, mathematics | Tagged , , , , , , , , , , , , , | 3 Comments

Use “banker’s rounding” and “normal rounding” in C#

By default the Math.Round method uses “banker’s rounding.” In banker’s rounding a number with a final digit of 5 is rounded to the nearest even number rather than to the next larger number as you might expect. The idea is … Continue reading

Posted in algorithms, mathematics | Tagged , , , , , , , , , , , , | Leave a comment