fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static void Main()
  6. {
  7. for (decimal x = 1 ; x != 2 ; x+=0.01M) {
  8. decimal y = CustomRound(x);
  9. Console.WriteLine("{0:0.00} {1:0.00}", x, y);
  10. }
  11. }
  12.  
  13. private static decimal CustomRound(decimal x)
  14. {
  15. var rX = Math.Truncate(x * 100) / 100;
  16. var t = rX * 100 % 5;
  17. if (t == 0) return rX;
  18. if (t < 3)
  19. rX = rX - ((decimal)t / 100);
  20. else if (t < 8)
  21. rX = rX + (((decimal)t / 100) - 0.05m);
  22. else
  23. rX = rX + ((decimal)t / 100);
  24. return rX;
  25. }
  26. }
Success #stdin #stdout 0.05s 26948KB
stdin
Standard input is empty
stdout
1.00 1.00
1.01 1.00
1.02 1.00
1.03 1.01
1.04 1.03
1.05 1.05
1.06 1.05
1.07 1.05
1.08 1.06
1.09 1.08
1.10 1.10
1.11 1.10
1.12 1.10
1.13 1.11
1.14 1.13
1.15 1.15
1.16 1.15
1.17 1.15
1.18 1.16
1.19 1.18
1.20 1.20
1.21 1.20
1.22 1.20
1.23 1.21
1.24 1.23
1.25 1.25
1.26 1.25
1.27 1.25
1.28 1.26
1.29 1.28
1.30 1.30
1.31 1.30
1.32 1.30
1.33 1.31
1.34 1.33
1.35 1.35
1.36 1.35
1.37 1.35
1.38 1.36
1.39 1.38
1.40 1.40
1.41 1.40
1.42 1.40
1.43 1.41
1.44 1.43
1.45 1.45
1.46 1.45
1.47 1.45
1.48 1.46
1.49 1.48
1.50 1.50
1.51 1.50
1.52 1.50
1.53 1.51
1.54 1.53
1.55 1.55
1.56 1.55
1.57 1.55
1.58 1.56
1.59 1.58
1.60 1.60
1.61 1.60
1.62 1.60
1.63 1.61
1.64 1.63
1.65 1.65
1.66 1.65
1.67 1.65
1.68 1.66
1.69 1.68
1.70 1.70
1.71 1.70
1.72 1.70
1.73 1.71
1.74 1.73
1.75 1.75
1.76 1.75
1.77 1.75
1.78 1.76
1.79 1.78
1.80 1.80
1.81 1.80
1.82 1.80
1.83 1.81
1.84 1.83
1.85 1.85
1.86 1.85
1.87 1.85
1.88 1.86
1.89 1.88
1.90 1.90
1.91 1.90
1.92 1.90
1.93 1.91
1.94 1.93
1.95 1.95
1.96 1.95
1.97 1.95
1.98 1.96
1.99 1.98