小弟刚学c,谁能告诉我怎么样将2.3 3.4之类的小数变成3和4 这样的整数

mybreeze 2003-05-07 08:53:29
小弟刚学c,谁能告诉我怎么样将2.3 3.4之类的小数变成3和4 这样的整数,但是想原来是整数的3.0 4.0 还是3 和4
强制类型转换(int)+1不能解决3.0 4.0问题
...全文
130 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
hproof 2003-05-07
  • 打赏
  • 举报
回复
如果我想把 PI = 3.1415926535897932384626433832795028841971…… 这样的长数精确到小数点后n位,不知道 floor/ceil 能不能做?

像这样?

floor(pi, n);
florr(-pi, n);
...
ghtsao 2003-05-07
  • 打赏
  • 举报
回复
Example
/* FLOOR.C: This example displays the largest integers
* less than or equal to the floating-point values 2.8
* and -2.8. It then shows the smallest integers greater
* than or equal to 2.8 and -2.8.
*/

#include <math.h>
#include <stdio.h>

void main( void )
{
double y;

y = floor( 2.8 );
printf( "The floor of 2.8 is %f\n", y );
y = floor( -2.8 );
printf( "The floor of -2.8 is %f\n", y );

y = ceil( 2.8 );
printf( "The ceil of 2.8 is %f\n", y );
y = ceil( -2.8 );
printf( "The ceil of -2.8 is %f\n", y );
}

Output
The floor of 2.8 is 2.000000
The floor of -2.8 is -3.000000
The ceil of 2.8 is 3.000000
The ceil of -2.8 is -2.000000

放分哦
gwsr 2003-05-07
  • 打赏
  • 举报
回复
引用C语言的数学函数:floor(x) 向下取整 ,ceil(x) 向上取整

24,860

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧