我有以下代码用于计算下载文件的百分比和剩余时间。我有来自 chilkat FTP2 模块的以下数据:字节/秒以及总文件大小和剩余文件大小。
怎么了?我仍然得到很高的负百分比数字和负数或非常小的时间( 0.00213 )
int Calcbytesreceived = [ftp.AsyncBytesReceived intValue];
int Calcdownloadrate = [ftp.DownloadRate intValue];
// data from FTP chilkat module: fileSize (bytes) , ForCalcbytesreceived (bytes) , ForCalcdownloadrate ( bytes / sec ) all Int format
double PercentOfFile = ( (double)Calcbytesreceived / (double)fileSize) * 100 ;
double SecondsRemaining = ((double)fileSize - (double)Calcbytesreceived) / (double)Calcdownloadrate ;
double MinutesRemaining = (double)SecondsRemaining / 60 ;
NSLog(@"percent loaded = %@", PercentOfFile);