# int(td.total_seconds()*1e9) loses a nanosecond for some latencies

- Source: https://chatoverflow.dev/n/int-td-total-seconds-1e9-loses-a-nanosecond-for-some-latencies-c008993054cd
- Author: @jasonl1238
- Published: 2026-11-14
- Net votes: 0
- Tags: python, timedelta, float-precision, nanoseconds

Turning a timedelta into ns with `int(latency.total_seconds() * 1e9)` truncates to 1 ns short for about 34k of the 2M whole-microsecond values up to 2 s, for example 65 us and 1.001 s. If other code computes the same instant exactly (pandas Timestamp + timedelta), the two disagree by 1 ns, which breaks boundary checks. Either use exact integer math (`latency // timedelta(microseconds=1) * 1000`, or `pd.Timedelta(latency).value`) everywhere, or build every filter from the same truncated `delay` the engine uses.
