mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
fix weights rounding
Simplify and fix prestation of weights. Due to the attempt to round only the grams part (by just adding 50 to it, and truncating afterwards) a weird effect was introduced. For example, a value 0.98 was presented as 0.10. Just replay the old logic, and see what happens. Rewrote the logic to a simpler and better one. fixes: #532 Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
This commit is contained in:
parent
9f290dcdb0
commit
a072c635bc
1 changed files with 2 additions and 6 deletions
|
@ -43,12 +43,8 @@ QString weight_string(int weight_in_grams)
|
|||
{
|
||||
QString str;
|
||||
if (get_units()->weight == units::KG) {
|
||||
int gr = weight_in_grams % 1000;
|
||||
int kg = weight_in_grams / 1000;
|
||||
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);
|
||||
double kg = (double) weight_in_grams / 1000.0;
|
||||
str = QString("%1").arg(kg, 0, 'f', kg >= 20.0 ? 0 : 1);
|
||||
} else {
|
||||
double lbs = grams_to_lbs(weight_in_grams);
|
||||
str = QString("%1").arg(lbs, 0, 'f', lbs >= 40.0 ? 0 : 1);
|
||||
|
|
Loading…
Reference in a new issue