Comp 110 double "Decimal"

double "Decimal"

What is a double?

  • A double is a data type that contains a decimal point
  • A double value can represent most decimal values we're likely to need in our programs (think 0.0, 0.1, 1.0,1234.56, 5.1x10^25 etc.)

double Literals

Double literals in Java are numbers that contain a decimal point:


Declaration and Initialization Syntax

As for all data types, declaring and initializing a double follows the syntax:

<type> <name> = <value>;

So, declaring and initializing a double looks like:

double valueOfAQuarter = 0.25;
double myGPA = 3.75;
double phoneBattery = 0.67 // in percent

Most useful for when you need percentages and more precise numbers.