gpt4 book ai didi

c - 如何将从文件扫描的数字 x 舍入到 i 小数位,从 C 中的同一文件扫描?

转载 作者:太空宇宙 更新时间:2023-11-04 06:42:42 24 4
gpt4 key购买 nike

R x i [圆形实数]将 double 值 x 舍入到 i 位有效小数位

例子:这是从文件中扫描的:R 3.1415 2
所以我需要打印出 3.14

做一个大循环,还有其他功能到目前为止:
否则如果(操作==“R”)printf("\n");

不知道该放什么...帮忙?

最佳答案

试试这个:

double number;
int places;
fscanf(file, "%lf %d", &number, &places);
printf("%.*f\n", places, number);

关于c - 如何将从文件扫描的数字 x 舍入到 i 小数位,从 C 中的同一文件扫描?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5780145/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com