Fricer

Comparing Floats

Jun 5th, 2014
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.62 KB | None | 0 0
  1. using System;
  2.  
  3.  
  4. class ComparingFloats
  5. {
  6.     static void Main()
  7.     {
  8.         System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
  9.  
  10.         Console.Write("Write a number a: ");
  11.         double a = double.Parse(Console.ReadLine());
  12.         Console.Write("Write a number b: ");
  13.         double b = double.Parse(Console.ReadLine());
  14.         double eps = 0.000001;
  15.  
  16.         if (Math.Abs(a - b) > eps)
  17.         {
  18.             Console.WriteLine("false");
  19.         }
  20.         else if (Math.Abs(a-b) < eps)
  21.         {
  22.             Console.WriteLine("true");
  23.         }
  24.  
  25.     }
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment