Made float have the correct number of decimal places

This commit is contained in:
TraYali 2024-03-18 23:53:47 +01:00
parent 30a39aff3e
commit d3d203842a

View file

@ -1,6 +1,8 @@
#include <cmath> #include <cmath>
#include <memory> #include <memory>
#include <mutex> #include <mutex>
#include <sstream>
#include <iomanip>
#include "modbus.h" #include "modbus.h"
@ -61,7 +63,9 @@ void PortParameterFloat::setValueFromRegisters(uint16_t *readArray, int register
std::string PortParameterFloat::getOutputValue() { std::string PortParameterFloat::getOutputValue() {
std::string separator{"_age"}; std::string separator{"_age"};
return std::to_string(this->value.f).append(separator.append(std::to_string(this->age))); std::stringstream valueStringStream;
valueStringStream << std::fixed << std::setprecision(this->decimalPlaces) << this->value.f;
return valueStringStream.str().append(separator.append(std::to_string(this->age)));
} }
PortParameterInt::PortParameterInt(std::string name, uint16_t parameterAddressOffset, int registerSize) : PortParameter(name, parameterAddressOffset, registerSize) { PortParameterInt::PortParameterInt(std::string name, uint16_t parameterAddressOffset, int registerSize) : PortParameter(name, parameterAddressOffset, registerSize) {