From: Clément de l'Hamaide Date: Tue, 30 Dec 2014 15:04:33 +0000 (+0100) Subject: Altimeter: fix output format for hPa/InHg settings X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=84a26de9ae9ade8629dee53cac8b9357f0930690;p=flightgear.git Altimeter: fix output format for hPa/InHg settings Usually, in a real cockpit, altimeter shows hPa setting as an integer number and InHg setting is limited to 2 decimals In aviation we don't need higher numeric precision --- diff --git a/src/Instrumentation/altimeter.cxx b/src/Instrumentation/altimeter.cxx index a691f1e90..00e6bb4b3 100644 --- a/src/Instrumentation/altimeter.cxx +++ b/src/Instrumentation/altimeter.cxx @@ -52,7 +52,7 @@ Altimeter::~Altimeter () double Altimeter::getSettingInHg() const { - return _settingInHg; + return int(_settingInHg*100.0)/100.0; /* return only 2 decimals: xx.xx */ } void @@ -61,14 +61,14 @@ Altimeter::setSettingInHg( double value ) _settingInHg = value; } -double +int Altimeter::getSettingHPa() const { - return _settingInHg * SG_INHG_TO_PA / 100; + return int(_settingInHg * SG_INHG_TO_PA / 100.0); /* return an INT: xxxx */ } void -Altimeter::setSettingHPa( double value ) +Altimeter::setSettingHPa( int value ) { _settingInHg = value * SG_PA_TO_INHG * 100; } diff --git a/src/Instrumentation/altimeter.hxx b/src/Instrumentation/altimeter.hxx index 45c3a4e61..a9b32d9a4 100644 --- a/src/Instrumentation/altimeter.hxx +++ b/src/Instrumentation/altimeter.hxx @@ -43,8 +43,8 @@ public: double getSettingInHg() const; void setSettingInHg( double value ); - double getSettingHPa() const; - void setSettingHPa( double value ); + int getSettingHPa() const; + void setSettingHPa( int value ); private: std::string _name;