Could we get an overload of `Duration.toString()` ...
# stdlib
c
Could we get an overload of
Duration.toString()
with only
decimals =
? I often want to display different durations but I don't particularly care about precision. The existing
toString()
forces me to specify the unit, but I want to keep the default 'choose the unit automatically' behavior. Example data:
Copy code
actualElapsed=100.355299ms
actualElapsed=203.587405ms
actualElapsed=304.010250ms
actualElapsed=404.457431ms
actualElapsed=505.196217ms
…
actualElapsed=1.412863722s
actualElapsed=1.514498612s
actualElapsed=1.615550814s
I'd prefer to display it as:
Copy code
actualElapsed=100.4ms
actualElapsed=203.6ms
actualElapsed=304.0ms
actualElapsed=404.5ms
actualElapsed=505.2ms
…
actualElapsed=1.4s
actualElapsed=1.5s
actualElapsed=1.6s
This is because in this particular situation, at-a-glance reading is more important than the precision of the value.
👍 2
👍🏻 1
👍🏼 1
k
In this situation, I would prefer significant figures instead of decimal places. If you're outputting durations of approximately 1 second, you don't want to end up with this:
Copy code
actualElapsed=995.2ms    -- could be between 995.15 and 995.25 ms - a range of 0.1 ms
actualElapsed=1.1s       -- could be between 1050 and 1150 ms     - a range of 100 ms
The durations are of very similar values, yet the precision is grossly different.
👍 3
👍🏻 1
c
Either is fine by me, I just want less verbose output.
f
CC @ilya.gorbunov
@CLOVIS could you please file an issue in YT?
c
Here it is: KT-86513 Format durations with a given number of significative digits
kodee loving 1