Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to limit the output variables in C++ to 1 digits after the decimal point?
How to limit the output variables in C++ to 1 digits after the decimal point?
Add cout

# Contains?

# Including

Use? Namespace? std

# Contains?

int? Master ()

{

Double? d? =? 12.5638;

cout? & lt& lt? setiosflags(ios::fixed)

& lt& lt? Setting accuracy (1)

Extended data:

The Language Foundation of c++

integer

Integer constant

Integer constants are numerical values without decimals, which are used to represent positive and negative numbers. Ox55, 0x55ff and 1000000 in Example 2-2 are all integer constants in c++ language.

There are three forms of integer constants in c++ language: decimal, octal and hexadecimal.

(1) Decimal integers are data consisting of numbers between 0 and 9 that do not start with 0.

(2) Octal integers are data consisting of numbers from 0 to 7 beginning with 0.

(3) Hexadecimal integers are data consisting of numbers from 0 to 9 starting from 0x or 0x and letters from A to F (both uppercase and lowercase letters are acceptable).

For example:

0,63,83 are decimal numbers.

00,077,0123 is an octal number.

0x0, Ox0, 0x53, 0x53, 0x3f and 0x3f are hexadecimal numbers.

The range of integer constants is limited, and its size depends on the type of such integers, regardless of the decimal form used.

Integer variable type

There are four types of integer variables: byte, short, int and long, all of which are signed integer variable types.

(1) byte type.

The byte type describes a signed 8-bit integer variable. Because different machines store multi-byte data in different ways, it may be from low byte to high byte, or from high byte to low byte. In this way, when analyzing network protocols or file formats, it is appropriate to use byte types to represent data in order to solve the problem of byte storage order on different machines.

(2) short type.

The short type describes a signed 16 bit integer variable. The short type limits the storage of data to storing high bytes first, and then storing low bytes.

(3)int type.

The int type describes a signed 32-bit integer variable. Int type is one of the most abundant and effective types. It is most commonly used for counting, array access and integer operation.

(4) long type.

Long describes a signed 64-bit integer variable. For large-scale calculation, large integers beyond the range of int are often encountered, so use long type.

& lt& lt? endl

Return? 0;

Baidu encyclopedia-c++

Baidu Encyclopedia-Variable