Fix roundings with lround()
This commit is contained in:
committed by
Jonas Kvinge
parent
d5b0794b00
commit
1a967597e8
@@ -21,6 +21,8 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QApplication>
|
||||
#include <QObject>
|
||||
@@ -539,7 +541,7 @@ QString RatingItemDelegate::displayText(const QVariant &value, const QLocale&) c
|
||||
if (value.isNull() || value.toDouble() <= 0) return QString();
|
||||
|
||||
// Round to the nearest 0.5
|
||||
const double rating = double(int(value.toDouble() * RatingPainter::kStarCount * 2 + 0.5)) / 2;
|
||||
const double rating = double(lround(value.toDouble() * RatingPainter::kStarCount * 2)) / 2;
|
||||
|
||||
return QString::number(rating, 'f', 1);
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
@@ -180,7 +181,7 @@ class RatingComparatorDecorator : public SearchTermComparator {
|
||||
public:
|
||||
explicit RatingComparatorDecorator(SearchTermComparator *cmp) : cmp_(cmp) {}
|
||||
bool Matches(const QString &element) const override {
|
||||
return cmp_->Matches(QString::number(static_cast<int>(element.toDouble() * 10.0 + 0.5)));
|
||||
return cmp_->Matches(QString::number(lround(element.toDouble() * 10.0)));
|
||||
}
|
||||
private:
|
||||
QScopedPointer<SearchTermComparator> cmp_;
|
||||
|
||||
Reference in New Issue
Block a user