Decimal Literals

Decimal literals are decimal values written directly in the program text.

Notation

There are two notations for writing decimals.

In general, if the sign is omitted, it is assumed to be +. Both a + and a - can be used.

There can be at most 15 decimal digits. If there are more than 15 digits, the number is rounded to 15 digits.

If there is a decimal point, there needs to be at least one digit before and after. The decimal point can be placed between any of the digits. The decimal point can also be placed first with a preceeding zero.

Ordinary notation

For example: -3 or 8.314462618.

Parts:

  • An optional sign.
  • 1-15 decimal digits with an optional decimal point.

Scientific notation

For example -1e12 or 6.67408e-11.

Parts:

  • An optional sign.
  • 1-15 decimal digits with an optional decimal point
  • the letter e, after which comes the exponent
  • an optional sign
  • a 1-2 decimal digit exponent