Re: [Cppcms-users] JSON integer conversion(s)
Brought to you by:
artyom-beilis
From: Artyom <art...@ya...> - 2010-06-30 10:02:16
|
Hello, Thanks for the good point you bring. Actually not only integer number were not printed correctly, but floating point ones as well. I fixed this that numbers are printed with maximal possible precision and this should solve problem (I also added test case for such numbers) So your example generates 1277880000 string and not 1.27788e+09 (changeset 1298, you can take if from SVN) > > I have noticed that the conversion of C++ integer numbers to json goes > trough converting it to a double. This can get undesired behavior for > large numbers when it automatic adds exponents when outputting it as > json. Double is capable representing integer numbers correctly, so the problem is not in converting them to double but rather in printing them. > > I want to keep the integer representation. If I want a double > representation I will convert it myself explicitly. > If possible by adding the function "void value::number(long int x);" > this issue can be solved. > This is not correct solution as neither JSON nor JavaScript have no integer or double type they have number type. So introducing "integer" type would be incorrect solution as it extends JSON object representation. IEEE floating point number can handle integer values correctly (with correct rounding and precision) so there no need to change internal representation. Also if you need real UUIDs neither integer nor double (and not even 64 bit integer) would be good enough. You should probably use string. Thanks for the report, Regards, Artyom |