You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi all, we are having an issue where we are trying to return 24.99 to the front end of our application (this is an amount for somebody to pay as we use a json representation of the payment standards ) which stipulate amount as a double (not a great idea but nothing we can do about it). The below code
#include <json/json.h>
#include <iostream>
using namespace std;
using namespace Json;
int main(int argc, char** argv) {
Value myNode(24.99);
std::cout << myNode.asString() << std::endl;
}
shows (on OS X) 24.989999999999998 (on Ubuntu we get 24.999999999999999 I think) anyhow this is a problem as it means unlike issue #85 we aren't round tripping to get the same value. We've no problem maintaining a branch to support this function but I've no idea what to do about this and am looking for some advice, we have thought about maybe storing precision with value and working that way but not convinced this would actually solve the problem. Any ideas would be massively appreciated!
Thanks
Christopher
The text was updated successfully, but these errors were encountered:
"...we aren't round tripping to get the same value."
How do you know that? There are many forms of literals that specify the quantity approximated by "24.99", which is inexact. The Json::Value constructor doesn't know you used "24.99". It just receives the bit pattern of the double that 24.99 creates, so there's no way to specify a "correct" asString() specification for it.
Hi Billy, oooo interesting result, sorry the library we are using on our head end is different and is interpreting this differently
#include <json/json.h>
#include <iostream>
using namespace std;
using namespace Json;
int main(int argc, char** argv) {
double myDouble=24.99;
Value myNode(myDouble);
Value myNodeFromStr;
Json::Reader reader;
reader.parse(myNode.asString(), myNodeFromStr, false);
std::cout << myDouble << std::endl;
std::cout << myNode.asString() << std::endl;
std::cout << myNodeFromStr.asDouble() << std::endl;
}
yields
24.99
24.989999999999998
24.99
so indeed using the same library all is well and in fact so it seems it works well from google chrome! ```
var x = 24.989999999999998; console.info("My test " + x.toString());
My test 24.99
I'll take this back to our terminal team! Thanks for making me extend the test!
Hi all, we are having an issue where we are trying to return 24.99 to the front end of our application (this is an amount for somebody to pay as we use a json representation of the payment standards ) which stipulate amount as a double (not a great idea but nothing we can do about it). The below code
shows (on OS X)
24.989999999999998
(on Ubuntu we get24.999999999999999
I think) anyhow this is a problem as it means unlike issue #85 we aren't round tripping to get the same value. We've no problem maintaining a branch to support this function but I've no idea what to do about this and am looking for some advice, we have thought about maybe storing precision with value and working that way but not convinced this would actually solve the problem. Any ideas would be massively appreciated!Thanks
Christopher
The text was updated successfully, but these errors were encountered: