Specifying floating point literals

A literal used to initialize a double is specified as a floating point by using either the scientific format, or simply by providing a decimal point:

    double one = 1.0;     double two = 2.;     double one_million = 1e6;

The first example indicates that the variable one is assigned to a floating-point value of 1.0. The trailing zero is not important, as shown in the second variable, two; however, the trailing zero does make the code more readable since the period is easy to overlook. The third example uses scientific notation. The first part is the mantissa and can be signed and the part after the e is the exponent. The exponent is the power-of-10 magnitude of the number (which can be negative). The variable is ...

Get Beginning C++ Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.