How to avoid TDateTime Data Rounding

前端 未结 2 1742
北荒
北荒 2021-01-21 10:11

I am writing column and cell classes for FMX TGrid that will contain TCalendarEdit and TTimeEdit instances in every cell. Everything works

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-21 11:13

    TDateTime is of type Double, which means it's a floating point value, and therefore is subject to the usual issues of binary representation when doing comparisons for equality without specifying an acceptable delta (difference)..

    Specifically for TDateTime values, you can use DateUtils.SameDateTime to compare equality down to less than one millisecond:

    FDate_Time.Modified := (FDate_Time.Modified) or
               (not SameDateTime(FDate_Time.FieldValue, 
                FCalendarEdit.Date + FTimeEdit.Time));
    

提交回复
热议问题