I want to round a value (double) to the next (all rounding time) number. Rounding can be determined by any number.
Exp .:
Round to the next 2.50
0.00 --> 0.00 0.01 --> 2.50 2.49 --> 2.50 2.50 --> 2.50 2.50000001 --> 5.00 ...
The algorithm for this is easy (if the "number" was negative * -1):
Math.Round((Math.Abs(number) + tolerance) / 2.50, MidpointRounding.AwayFromZero) * 2.50
Tolerance is defined as follows:
tolerance = 2.50 / 2 - Math.Pos(10, -x);
But I do not know how to determine x! Because in the case of the 1st-4th example, x should be 0.01 in the case of the 5th example, it should be 0.0000001 and so on ...
The search results only allow you to analyze the string of a decimal number and calculate the decimal digit. Is there a mathematical way? Otherwise, I will have to process various locale settings for the decimal separator and numbers without decimal digits (not required to remove the decimal separator).
Does anyone have a solution for my problem. Thanks!
Regards, Danny
source share