我有一个while循环,每次运行大约1000万次递增变量"day".我希望程序只在一百万天过后打印一条线(即
100万天过去了
200万天过去了
...
循环完成
到目前为止我有代码:
double dayMill; //outside the loop
...
dayMill = day/1000000; //every runthrough of the loop
Run Code Online (Sandbox Code Playgroud)
我正在考虑使用if语句
if( (int)dayMill == dayMill){}
Run Code Online (Sandbox Code Playgroud)
因为当天= 1,000,000然后daymill = 1所以作为一个int,它也是1.但这不起作用.它打印了0.0百万天...很多,直到1.0很多.....从来没有我想要的每一百万行的一行
if(dayMill % 1000000 == 0)
{
//print statement
}
Run Code Online (Sandbox Code Playgroud)
那就是你让dayMill成为一个int.如果你加1,为什么它是双倍?我想我真的不明白你在做什么.