Skip to content

Output multiprecision as a number instead of a string #565

Answered by danielaparker
eungenue asked this question in Q&A
Discussion options

You must be logged in to vote

Apologies, I think I misunderstood your question!

You can output a string tagged with semantic_tag::bigint or semantic_tag::bigdec with a bigint_chars_format::number option, viz:

    std::string s = "[100000000000000000000000000000000.1234]";
    auto options = json_options{}
        .lossless_number(true)
        .bigint_format(bigint_chars_format::number);
    json j = json::parse(s, options);

    std::cout << print(j,options) << "\n"; // or pretty_print

Output:

[100000000000000000000000000000000.1234]

It's arguable that that should be the default, as you suggest, that would be more consistent. bigint_format and bigint_chars_format would also have been better named bignum_format and b…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by eungenue
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants