Difference between Double and Float in C

Double and Float:

On this page we will discuss about the difference between double and float in C programming language.

Difference between Double and Float in C

Definitions:

Double

  • In programming languages, this is the most used data type for assigning values with a real or decimal-based number within, such 3.14 for pi.
  • It has two times as much precision as a float, or double precision.
  • Double type variables can be given a value that falls between the ranges of 2.3E-308 and 1.7E+308.
  • Double requires storage of 8 bytes.
  • It has a precision of 15 decimal places.
  • It features a 64-bit floating point precision, according to IEEE.

Float

  • This is typically used for graphic-based libraries since it makes it easier for compilers to manage your programs’ processing capacity.
  • Float has single precision.
  • The storage required by Float is 4 bytes.
  • Float variables can be given a value with a range of 1.2E-38 to 3.4E+38.
  • It features a 32-bit floating point precision, according to IEEE.
  • It has a precision of six decimal places.
FloatDouble
Float requires storage of 4 bytes.Double requires storage of 8 bytes.
It features a 32-bit floating point precision, according to IEEE.It features a 64-bit floating point precision, according to IEEE.
It has a precision of 6 decimal places.It has a precision of 15 decimal places.
Float variables can be given a value with a range of 1.2E-38 to 3.4E+38.Double type variables can be given a value that falls between the ranges of 2.3E-308 and 1.7E+308.
Float has single precision.Double has two times as much precision as a float, or double precision.

Example of Float and Double:

Run
#include<stdio.h>
int main ()
{
  int a = 12, b = 25, sum;
  float c = 11.23, d = 15.23, add;
  sum = a + b;
  add = c + d;
  printf ("The sum of a and b is : %d\n", sum);
  printf ("The sum of c and d is : %d", add);
  return 0;
}

Output:

The sum of a and b is : 37
The sum of c and d is : -11046240

Example of Float:

Run
#include<stdio.h>
int main ()
{
  double a, b, Result;
  printf ("Enter two numbers = ");
  scanf ("%lf %lf", &a, &b);
  Result = a * b;
  printf ("Result = %.2lf", Result);
  return 0;
}

Output:

Enter two numbers = 4
8
Result = 32.00

Example of Double:

Run
#include 
double feetToMeter (double feetInput)
{
  return feetInput / 3.28;
}
int main ()
{
  double feetInput;
  double meterValue;
  printf ("Input the value in feet = ");
  scanf ("%lf", &feetInput);
  meterValue = feetToMeter (feetInput);
  printf ("The value in meter is = %lf", meterValue);
  return 0;
}

Output:

Input the value in feet = 6
The value in meter is = 1.829268

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription