private double round(Double d) { if (d < 0) { return 0.0; } if (d > 1) { return 1.0; } else { return Math.Round(d); } }