diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2016-02-24 08:20:24 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2016-02-24 08:20:24 +0100 |
commit | 86ec3d06a233e77d0b3a84d71c1d23669652d8a6 (patch) | |
tree | 0951e6321f7e821d94f6f5fde4ebdaecbf58a5d5 | |
parent | 6d52d0f7618f4b4b42c3b0e543ef5891abdd4f0d (diff) | |
download | subsurface-86ec3d06a233e77d0b3a84d71c1d23669652d8a6.tar.gz |
Correctly round total weight displayed
The code was wrong (and in the case of metric display for weights >= 20kg,
spectacularly wrong) in more or less all cases.
Rounding. It's good for the sole.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | subsurface-core/qthelper.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/subsurface-core/qthelper.cpp b/subsurface-core/qthelper.cpp index 5c48573cc..bfc7fc57b 100644 --- a/subsurface-core/qthelper.cpp +++ b/subsurface-core/qthelper.cpp @@ -44,13 +44,16 @@ QString weight_string(int weight_in_grams) if (get_units()->weight == units::KG) { int gr = weight_in_grams % 1000; int kg = weight_in_grams / 1000; - if (kg >= 20.0) { - str = QString("0"); - } else { - str = QString("%1.%2").arg(kg).arg((unsigned)(gr) / 100); - } + if (kg >= 20.0) + str = QString("%1").arg(kg + (gr >= 500 ? 1 : 0)); + else + str = QString("%1.%2").arg(kg).arg((unsigned)(gr + 50) / 100); } else { double lbs = grams_to_lbs(weight_in_grams); + if (lbs >= 40.0) + lbs = rint(lbs + 0.5); + else + lbs = rint(lbs + 0.05); str = QString("%1").arg(lbs, 0, 'f', lbs >= 40.0 ? 0 : 1); } return (str); |