Advertisement
remote87

Comparing Floats

Sep 6th, 2015
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6. using System.Globalization;
  7.  
  8. namespace _13.ComparingFloats
  9. {
  10.     class ComparingFloats
  11.     {
  12.         static void Main()
  13.         {
  14.             System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
  15.             Console.WriteLine("Enter first number:");
  16.             double firstNum = double.Parse(Console.ReadLine());
  17.             Console.WriteLine("Enter second number:");
  18.             double secondNum = double.Parse(Console.ReadLine());
  19.             double eps = 0.000001;
  20.             if (Math.Abs(firstNum - secondNum) < eps)
  21.             {
  22.                 Console.WriteLine("The numbers are similar or equal.");
  23.             }
  24.             else if (Math.Abs(firstNum - secondNum) > eps)
  25.             {
  26.                 Console.WriteLine("The numbers are NOT equal.");
  27.             }
  28.             else
  29.             {
  30.                 Console.WriteLine("Wrong input.");
  31.             }
  32.  
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement