+ if (stream.numberFlags() & QTextStream::ForceSign)
+ ss << showpos;
+
+ if (0 == precision)
+ ss << setprecision(1) << round(t);
+ else
+ ss << setprecision(precision) << t;
+
+ string str(ss.str());
+ if (0 == precision) {
+ // remove the separator and the unwanted decimal place
+ str.resize(str.size() - 2);
+ }
+
+ return stream << QString::fromStdString(str);
+}
+
+QString format_time_si(const Timestamp& v, SIPrefix prefix,
+ unsigned int precision, QString unit, bool sign)
+{
+ if (prefix == SIPrefix::unspecified) {
+ // No prefix given, calculate it
+
+ if (v.is_zero()) {
+ prefix = SIPrefix::none;
+ } else {
+ int exp = exponent(SIPrefix::yotta);
+ prefix = SIPrefix::yocto;
+ while ((fabs(v) * pow(Timestamp(10), exp)) > 999 &&
+ prefix < SIPrefix::yotta) {
+ prefix = successor(prefix);
+ exp -= 3;
+ }
+ }
+ }
+
+ assert(prefix >= SIPrefix::yocto);
+ assert(prefix <= SIPrefix::yotta);
+
+ const Timestamp multiplier = pow(Timestamp(10), -exponent(prefix));