fork(3) download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static void Main()
  6. {
  7. double d = -0.99999999999999956d;
  8. decimal result = Convert.ToDecimal(d); // Result = -1
  9. decimal t = 0M;
  10. bool b = d < 0;
  11. if (b) d = -d;
  12. if (d >= 0.5) { d -= 0.5; t += 0.5M; }
  13. if (d >= 0.25) { d -= 0.25; t += 0.25M; }
  14. if (d >= 0.125) { d -= 0.125; t += 0.125M; }
  15. if (d >= 0.0625) { d -= 0.0625; t += 0.0625M; }
  16. t += Convert.ToDecimal(d);
  17. if (b) t = -t;
  18. Console.WriteLine(t);
  19. }
  20. }
Success #stdin #stdout 0.05s 34856KB
stdin
Standard input is empty
stdout
-0.9999999999999996