Boost logo

Boost Users :

From: Pavel Vazharov (freakpv_at_[hidden])
Date: 2023-02-24 09:48:27


Hi there,

Looking at the source code of boost::json this behavior doesn't seem
customizable because it calls - detail::format_double in
serializer::write_number and the former further calls ryu::d2s_buffered_n.
I could be missing something here, though. So it's probably better to wait
for more opinions on the subject.
On the other hand, you can always serialize the json::value manually in a
way similar to the one shown in this example -
https://www.boost.org/doc/libs/1_81_0/libs/json/doc/html/json/examples.html#json.examples.pretty
.
This way you'll have control how exactly you want to display the float
values.

HTH,
Pavel.

On Fri, Feb 24, 2023 at 11:25 AM Markus Pieper via Boost-users <
boost-users_at_[hidden]> wrote:

> Hi there,
>
> I convert a std::vector<std::vector<float>> to a JSON string. Basically it works, but the format is scientific:
> "[[1.017E3,1.017E3,1.017E3 ... ]]"
>
> My method looks now like this:
>
> std::string Class::convertFieldAsJSON(std::vector<std::vector<float>> field) {
> return boost::json::serialize(boost::json::value_from(field));
> }
>
> It works, but my colleagues want to see a 1017 and not 1.017E3 in the output.
> Is there a way to format the string?
>
> Thanks in advance,
> Markus
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> https://lists.boost.org/mailman/listinfo.cgi/boost-users
>



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net