Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - C language: How to keep one decimal place or two decimal places when outputting the result?
C language: How to keep one decimal place or two decimal places when outputting the result?

Use fixed-point format.

The float type %.2f means 2 decimal places, and %.1f means 1 decimal place.

For double type, %.2f means 2 decimal places, and %.1f means 1 decimal place.

For double type, %.2lf means 2 decimal places, and %.1lf means 1 decimal place.

Extended information

Arithmetic operators

are used for various numerical operations. Including addition (+), subtraction (-), multiplication (*), division (/), remainder (or modular operation, %), self-increment (++), self-decrement (--)*** seven types .

Relational operators

are used for comparison operations. Including greater than (>), less than (<), equal to (==), greater than or equal to (>=), less than or equal to (<=) and not equal to (!=).

Logical operators

Used for logical operations. Including and (&&), or (||), not (!).

Bit operation operators

The quantities involved in the operation are operated on binary bits. Including six types: bitwise AND (&), bitwise OR (|), bitwise NOT (~), bitwise XOR (^), left shift (<<), and right shift (>>).

Assignment operator

It is used for assignment operations and is divided into simple assignment (=), compound arithmetic assignment (+=,-=,*=,/=,%=) and There are three types and eleven types of compound bit operation assignment (&=, |=, ^=, >>=, <<=).