profile
viewpoint

Ask questionsFloat formatting when writting output

Hello,

I'm trying to save some float values into an Array in a Document and then to save it into a json file. I need a precision of 12 so I used writer.SetMaxDecimalPlaces(12); It works in most cases but if there are 6 zeros or more, the writer uses the exponential notation, which I don't want at all.

just a little example: `float value = 0.000000134110; // 6 zeros : exponential float value2 = 0.00000134110; // 5 zeros ok float value3 = 0.0134110; // ok float value4 = 0.013411025745467674374; // too long : truncate ok

Document doc(kArrayType); doc.PushBack(Value(value).Move(), doc.GetAllocator()); doc.PushBack(Value(value2).Move(), doc.GetAllocator()); doc.PushBack(Value(value3).Move(), doc.GetAllocator()); doc.PushBack(Value(value4).Move(), doc.GetAllocator());

// write into a file StringBuffer buffer; Writer<StringBuffer> writer(buffer); writer.SetMaxDecimalPlaces(12); // to have the good precision doc.Accept(writer); const char* output = buffer.GetString(); FILE *out; out = fopen("essai.json", "w"); if (out != NULL){ fprintf(out, "%s", output); fclose(out); `

the final essai.json is the following: [1.3410999599727803e-7,0.000001341099,0.01341100037,0.013411025516]

Has anyone an idea to avoid the exponential notation ?

Thanks

Tencent/rapidjson

Answer questions miloyip

It seems to be a bug. Do you want to try to fix it and submit a PR?

useful!

Related questions

是否支持流式解析以及多个json分离解析 hot 1
是否支持流式解析以及多个json分离解析 hot 1
RapidJSON causes cc1plus: internal compiler error: Segmentation fault - rapidjson hot 1
GenericMemberIterator::Iterator implicitly declared private when RAPIDJSON_NOMEMBERITERATORCLASS is defined hot 1
Always gets a core dump while creating json string (rapidjson) hot 1
Bazel Support hot 1
Syntax typo in tutorial hot 1
是否支持流式解析以及多个json分离解析 hot 1
作者你好,我 想请教一下,这个框架是否能够将变量中文stirng 转成wchar_t? 在文档只看到定量 hot 1
travis on windows hot 1
Added headers to my project and got thousands of errors hot 1
Added headers to my project and got thousands of errors hot 1
想要的反斜杠 \. 无法表示,否则JSON解析出错 hot 1
Assertion `stack_.GetSize() == sizeof(ValueType)' failed hot 1
source:https://uonfu.com/
Github User Rank List