From 16ccc43d7a7eb19f00e7abe4f28143d0c013bdf9 Mon Sep 17 00:00:00 2001 From: enngq11k <148800743+enngq11k@users.noreply.github.com> Date: Mon, 25 Mar 2024 19:45:18 +0100 Subject: [PATCH] Fixed rounding error on loading and saving erg files (#4455) --- src/Train/ErgFile.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Train/ErgFile.cpp b/src/Train/ErgFile.cpp index 2d97214d3..cbcfa89ec 100644 --- a/src/Train/ErgFile.cpp +++ b/src/Train/ErgFile.cpp @@ -26,6 +26,7 @@ #include #include +#include #include "Units.h" #include "Utils.h" @@ -599,13 +600,12 @@ void ErgFile::parseComputrainer(QString p) switch (format) { case ERG: // its an absolute wattage - if (Ftp) { // adjust if target FTP is set. + if (Ftp && Ftp != CP) { // adjust if target FTP is set. // if ftp is set then convert to the users CP - double watts = add.y; double ftp = Ftp; watts *= CP/ftp; - add.y = add.val = int(watts); + add.y = add.val = int(std::round(watts)); } break; case MRC: // its a percent relative to CP (mrc file) @@ -1264,7 +1264,9 @@ ErgFile::save(QStringList &errors) double minutes = double(p.x) / (1000.0f*60.0f); // we scale back if needed - if (Ftp && CP) watts = (double(p.y)/CP) * Ftp; + if (Ftp && CP && Ftp != CP) { + watts = std::round(p.y / CP * Ftp); + } // check if a lap marker should be inserted foreach(ErgFileLap l, Laps) {