#define KB 1024
#define MB (1024*KB)
#define GB (1024*MB)
void CDemoDlg::OnTest()
{
int nNum1 = GetDlgItemInt(IDC_NUM1);
CString strNum2 = _T("");
//转换成GB
if (nNum1 > GB)
{
strNum2.Format(_T("%0.2fGB"), (double)nNum1 / GB);
}
//转换成MB
else if (nNum1 > MB)
{
strNum2.Format(_T("%0.2fMB"), (double)nNum1 / MB);
}
//转换成KB
else if (nNum1 > KB)
{
int n = nNum1 / KB;
strNum2.Format(_T("%0.2fKB"), (double)nNum1 / KB);
}
else
{
strNum2.Format(_T("%dByte"), nNum1);
}
SetDlgItemText(IDC_NUM2, strNum2);
}