作者:admin 来源: 日期:2020/10/13 8:49:46 人气: 标签:
最近写刻录程序时用到了int64计算比例的功能,integer的范围是4G,而普通DVD光盘容量就是4.3G,直接计算是通不过编译的
因此用了一种取巧的方法,把两个数据右移16位,然后计算比例,当数据小于2的16次方(64k,接近VCD容量的万分之一)时,当作最小进度(如1%)处理
代码如下:
function GetProgress: Integer;var nReadSize, nCapibility: Integer;begin nReadSize := Integer(FWriteSize shr 16); nCapibility := Integer(FCapibility shr 16 ); Result := Round( (nReadSize / nCapibility) * 100 ); if (Result = 0) and (nReadSize > 0) then Result := 1;end;
https://blog.csdn.net/youthon/article/details/7963161