• 关于数据库中浮点运算、保留小数和时间计算


    关于小数:

        1SQL数据表中使用numeric字段时(一定要注明小数位数),程序中使用:ADOQuery1.FieldByName('price').Value := RoundEx((ADOQuery1.FieldByName('price').AsFloat + strtofloat(Edit1.text)) * 1000) / 1000;或者ADOQuery1.FieldByName('price').Value:=adoquery1.FieldByName('price').AsFloat+strtofloat(edit1.Text);都可以保证数据计算的精度是准确值

    2SQL数据表中使用float字段时,程序中使用ADOQuery1.FieldByName('price').Value := RoundEx((ADOQuery1.FieldByName('price').AsFloat + strtofloat(Edit1.text)) * 1000) / 1000;才可以保证精度;而使用:ADOQuery1.FieldByName('price').Value:=adoquery1.FieldByName('price').AsFloat+strtofloat(edit1.Text);就会出现浮点小数,使得计算结果不准确。

    以上结果最多经过90000次循环测试。

    关于次幂:

        Delphi中可以直接使用Power函数计算某个数的次幂,但是需要在Uses中加入uses math;函数用法:i:=Power(10,2);表示10的平方。

    关于时间:

    当要进行时间加减运算时,其计算结果是天为单位,如果需要换算成秒,则需要进行如下运算:

    Edit6.Text:=floattostr(roundex((strtodatetime(edit5.Text)-strtodatetime(edit2.Text))*86400*100)/100);

    注:(124小时,1小时60分钟,1分钟60秒,因此86400=24*60*60

  • 相关阅读:
    Linux进阶之bond链路聚合
    Linux服务之cobbler批量部署篇
    Linux进阶之排错
    shell基础之综合练习
    shell基础之99乘法表
    Linux进阶之VMware Linux虚拟机运行提示“锁定文件失败 虚拟机开启模块snapshot失败”的解决办法
    Linux服务之DNS服务篇
    linux服务之NTP及chrony时间同步
    八大排序算法汇总
    堆排序
  • 原文地址:https://www.cnblogs.com/bingege/p/2147959.html
Copyright © 2020-2023  润新知