mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-07-04 10:37:11 +02:00
address the double to json format accounting for integer side number of digits
This commit is contained in:
parent
b4d2b65841
commit
a89dec25ad
@ -141,8 +141,11 @@ std::string valueToString(double value, bool useSpecialFloats, unsigned int prec
|
|||||||
char buffer[32];
|
char buffer[32];
|
||||||
int len = -1;
|
int len = -1;
|
||||||
|
|
||||||
|
int length = (value==0.0)?1:(int)(std::floor(std::log10(std::abs(value)))+1);
|
||||||
|
if (length<1) length=1;
|
||||||
|
|
||||||
char formatString[6];
|
char formatString[6];
|
||||||
sprintf(formatString, "%%.%dg", precision);
|
sprintf(formatString, "%%.%dg", precision-length);
|
||||||
|
|
||||||
// Print into the buffer. We need not request the alternative representation
|
// Print into the buffer. We need not request the alternative representation
|
||||||
// that always has a decimal point because JSON doesn't distingish the
|
// that always has a decimal point because JSON doesn't distingish the
|
||||||
|
Loading…
x
Reference in New Issue
Block a user