In C language, you can obtain the two digits after the decimal point of a floating-point number by following the following steps: Multiply the floating-point number by 100 to turn the decimal part into an integer. Use the / operator to divide a floating point number by 100, rounding off the integer part. Use the % operator to get the decimal part of a floating point number modulo 100.
Take two digits after the decimal point in C language
In C language, you can use the truncated division operation Use the /
operator and the modulo operator %
to obtain the decimal part of a floating point number.
Steps:
/
operators to divide a floating point number by 100 and round the integer part. %
operator to make the floating point number modulo 100 and get the decimal part. Sample code:
1 2 3 4 5 6 7 8 9 10 11 |
|
Output:
1 |
|
The above is the detailed content of How to express two digits after decimal point in C language. For more information, please follow other related articles on the PHP Chinese website!