【发布时间】:2021-04-11 17:48:57
【问题描述】:
在问题中,如何将浮点数舍入到用户指定的小数位数?我当前的代码仅将浮点数打印到小数点后 2 位。另外,是否有用于此目的的内置函数?
#include <stdio.h>
int main()
{
float x = 1.2345;
int dp;
printf("The float is: %f. How many decimal points to round to? ", x);
scanf("%d", &dp);
printf("Number: %.2f", x);
}
【问题讨论】:
标签: c floating-point rounding