如何编写带有循环、+ - * /和%(取模)的RoundDown()函数



我只是在想,如果你只有循环,+ - */和%(模)。有可能将浮点数舍入到下一个整数吗?
例如278.791到278?

我已经考虑了很长时间了,但仍然找不到解决办法。这可能吗?

在Python中% works:

#!/usr/bin/python
x = 278.791
y = x - (x % 1)
print x, y

在C语言中必须使用其他方法:

#include <stdio.h>
#include <math.h>
int main() {
    float x = 278.791;
    float y = fmod(x,1.0);
    printf("%f, %fn", x, y);
    x = 278.791;
    y = x - (int)x;
    printf("%f, %fn", x, y);
}

最新更新