How would I go about round off floats ONLY to multiples of 0.025
So for example: 1.041 would be rounded off to 1.05
I know how to round off floats in C# but only to decimal values.
How would I go about round off floats ONLY to multiples of 0.025
So for example: 1.041 would be rounded off to 1.05
I know how to round off floats in C# but only to decimal values.
Modified from here
public static float QuarterTenthsRound(this float number)
{
var decimalPlaces = number - (int)number;
float wholeNumber = (float)((Math.Round((decimalPlaces * 10) * 4,
MidpointRounding.ToEven) / 4) / 10);
return (int)number + wholeNumber;
}
I used it as an extension method, so myFloat.QuarterTenthsRound()
would be the usage.
You could use a function like this:
public static decimal Round(decimal value)
{
var ceiling = Math.Ceiling(value * 400);
return ceiling / 400;
}