From b838691f50ecd639c9a6d8a675e8d8986d4f2b49 Mon Sep 17 00:00:00 2001 From: ThorstenB Date: Wed, 10 Oct 2012 20:28:17 +0200 Subject: [PATCH] #897: float vs double precision issues (frequency dialog not always working) puObject only provides float, not double, which causes precision/rounding issues with some numerical values (try "114.2"). Work around: obtain string value, and manually convert with proper double precision. --- src/GUI/FGPUIDialog.cxx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/GUI/FGPUIDialog.cxx b/src/GUI/FGPUIDialog.cxx index 9b2bc232a..3555d5039 100644 --- a/src/GUI/FGPUIDialog.cxx +++ b/src/GUI/FGPUIDialog.cxx @@ -491,9 +491,17 @@ copy_from_pui (puObject *object, SGPropertyNode *node) node->setIntValue(object->getIntegerValue()); break; case props::FLOAT: - case props::DOUBLE: node->setFloatValue(object->getFloatValue()); break; + case props::DOUBLE: + { + // puObject only provides float, not double, which causes precision/rounding issues + // with some numerical values (try "114.2"). + // Work around: obtain string value, and manually convert with proper double precision. + const char *s = object->getStringValue(); + node->setDoubleValue(atof(s)); + break; + } default: const char *s = object->getStringValue(); if (s)