Skip to content

Time::As() time display precision

We have a convention to use Time::As() in NS_LOG statements, but I cannot find any API to disable scientific notation, which causes a loss of precision.

For instance, this code added to scratch-simulator.cc:

+  Time t = Seconds (3) + MicroSeconds (1);
+  NS_LOG_UNCOND (t.As (Time::S));
+  NS_LOG_UNCOND (t.As (Time::US));
+  NS_LOG_UNCOND (t.As (Time::NS));

yields:

+3s
+3e+06us
+3e+09ns

I would rather have:

+3.000001s
+3000001us
+3000001000ns

I kind of consider this to be a bug, because it causes me to misinterpret logs sometimes.