double cost1;//定以每小时的上机费用
 cost1=atof(m_set3.m_hour_price1);//m-set3.m-hour-price1是存在数据哭里的每小时单价CTimeSpan t1(m_set2.m_first_time.GetDay(),m_set2.m_first_time.GetHour(),m_set2.m_first_time.GetMinute(),m_set2.m_first_time.GetSecond());
    st1[count]=t1;    CTimeSpan t2(m_set2.m_end_time.GetDay(),m_set2.m_end_time.GetHour(),m_set2.m_end_time.GetMinute(),m_set2.m_end_time.GetSecond());
    CTimeSpan  totaltime;

    st2[count]=t2;    totaltime=st2[count]-st1[count];//得到上机的总时间
    //下面开始计算上机费用,每小时价格/3600*总的秒数=上机费用
    Spendmoney=totaltime.GetTotalSeconds()*cost1/3600;
    //但是为什么在列表里价钱显示总是零了?
    tmp_str.Format("%f",Spendmoney);
    m_list1.SetItemText(select_id,6,tmp_str);    //上机时间可以正确显示
    tmp_str=totaltime.Format("%H:%M:%S");
    m_list1.SetItemText(select_id,5,tmp_str);

解决方案 »

  1.   

    跟踪条是一下
    看看Spendmoney = totaltime......
    执行过后Spendmoney的值是多少?
      

  2.   

    我修改了一下,基本没改,运行没有问题,你从数据库中读出的内容有问题吧。 double cost1 = 2.00;//定以每小时的上机费用
    //cost1=atof(m_set3.m_hour_price1);//m-set3.m-hour-price1是存在数据哭里的每小时单价 CTime first(2003, 5, 7, 10 , 0 ,0);
    CTime end(2003, 5, 7,  12, 25, 0); CTimeSpan t1(first.GetDay(),first.GetHour(),first.GetMinute(),first.GetSecond());
            CTimeSpan t2(end.GetDay(),end.GetHour(),end.GetMinute(),end.GetSecond());
        CTimeSpan  totaltime;
    CString tmp_str;    totaltime=t2 - t1;//得到上机的总时间
        //下面开始计算上机费用,每小时价格/3600*总的秒数=上机费用
        double Spendmoney=totaltime.GetTotalSeconds()*cost1/3600;
        //但是为什么在列表里价钱显示总是零了?
        tmp_str.Format("%f",Spendmoney);
        MessageBox(tmp_str);    //上机时间可以正确显示
        tmp_str=totaltime.Format("%H:%M:%S");
        MessageBox(tmp_str);
      

  3.   

    Spendmoney是不是定义成int型的了,跟踪一下,看看Spendmoney的值