【发布时间】:2011-04-10 00:15:20
【问题描述】:
在C++ C中:输出:“1610612736”
#include <math.h>
#include <stdio.h>
int main(int argc, char** argv)
{
printf("%d\n", fmodf(5.6f, 6.4f));
getchar();
}
在 C# 中:输出:“5.6”
using System;
static class Program
{
public static void Main(string[] args)
{
Console.WriteLine(5.6f % 6.4f);
Console.Read();
}
}
显然不一样的输出。有什么建议吗?
【问题讨论】:
-
%d 用于十进制。如果您使用 C++,请使用流来避免此类问题。
-
顺便说一句,这是 C 代码,而不是 C++。在 C++ 中使用
<cmath>、<cstdio>和std::fmod。 -
@Alexandre C:它被标记为 C++。
-
这篇文章不应该被标记为“FMOD”,这个标签是关于称为FMOD的跨平台音频中间件,而不是浮点模数函数。
-
感谢您编辑我的帖子并更改标签。我想将它标记为“fmodf”,只是这个标签不存在,而且我没有足够的声誉来创建它。