In C#:
public static double Round(double x, int numerator, int denominator)
{ // returns the number nearest x, with a precision of numerator/denominator
// example: Round(12.1436, 5, 100) will round x to 12.15 (precision = 5/100 = 0.05)
int y = (int)Math.Round(x * denominator + (double)numerator / 2.0);
return (double)(y - y % numerator)/(double)denominator;
}
In Euphoria:
global function Round(atom x, integer numerator, integer denominator)
-- returns the number nearest x, with a precision of numerator/denominator
-- example: Round(12.1436, 5, 100) will round x to 12.15 (precision = 5/100 = 0.05)
integer y
y = floor(x * denominator + numerator / 2.0 + 0.5)
return (y - remainder(y, numerator)) / denominator
end function