Skip to content

Format units

Max Holicki requested to merge FormatUnits into master

Goal: Format values according to SI or IEC unit prefixes such that scaling occurs dynamically. Currently the units are hard coded in the source code which leads to sometimes funny results if time were expected in the seconds, but times were in the micro seconds. With four digits after the decimal separator it would have looked like 0.0000 s. For numbers outside the SI or IEC ranges respectively exponential e notation. Here is some corrected example output:

SI:  +3.141593e+00 s->  +3.14159  s
SI:  +3.141593e+05 s->+314.15927 ks
SI:  +3.141593e+10 s-> +31.41593 Gs
SI:  +3.141593e+15 s->  +3.14159 Ps
SI:  +3.141593e+20 s->+314.15927 Es
SI:  +3.141593e+25 s->+3.14e+025  s
SI:  +3.141593e-05 s-> +31.41593 us
SI:  +3.141593e-10 s->+314.15926 ps
SI:  +3.141593e-15 s->  +3.14159 fs
SI:  +3.141593e-20 s-> +31.41593 zs

IEC: +3.141593e+00 B->   +3.1416   B
IEC: +3.141593e+10 B->  +29.2584 GiB
IEC: +3.141593e+20 B-> +272.4897 EiB
IEC: +3.141593e+30 B-> +3.1e+030   B
IEC: +1.047552e+06 B->+1023.0000 kiB
Edited by Max Holicki

Merge request reports