.net - How do I round a decimal to a specific fraction in C#? -


Number is easy in C #:

  math.Round (1.23456, 4) ; // Return 1.2346 However, I want to round one number, as if the fraction of the number is to the nearest partial part of a predefined fraction (i.e. 1/8th) and i 'nat library is already built in it I am trying to find out.  

For example, if I want to score a decimal number round to the eighth place, then I want to do something like this:

  math.Round fractional (1 9, 8); // And it's yield 1.875 monastery. Round Fractional (1.95, 8); // And this yield is 2.0  

Then the first paragraph is the number that I want to round and the second parameter points to the round fragment. So in this example, after rounding the figures have come after decimal numbers, only one of the eight values ​​can be: .000, .125, .250, .375, .500, .625, .750, .875 < / P>

Question: Has this function been created somewhere in .NET? If not, then does anyone have a link to a resource that explains how to approach this problem?

can do this:

  math.read (n * 8) / 8.0  

Comments