Double Variable in C

Level 255 keystrokes

Stores the price 19.99 in a double and prints it with two decimals after a dollar sign: "Price: $19.99".

C code

// double has about twice the precision of float; a literal without f, like 19.99, is a double
1double price = 19.99;
// $ is printed as is; %.2lf shows the double with 2 decimals
// (in printf, %lf and %f both print a double)
2printf("Price: $%.2lf\n", price);

Output

Price: $19.99
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this C code and how often they appear.

  • ;× 2
  • .× 2
  • "× 2
  • ,× 1
  • :× 1
  • (× 1
  • )× 1
  • \× 1
  • %× 1
  • =× 1

More C examples at level 2

← C typing practice