// double has 53 bit significant, therefore 2^53=9007199254740992
// is the largest integer that can be represented. For a floating
// point value, that consumes more than 16 characters may result
// in precision loss during conversion. Note that we are being
// pessimistic in that some floating point values that consume
// 17 characters may be represented without conversion loss.
if ( json->cfg->decode_big_numbers_as_strings &&
( endptr - json->ptr > 16 ||
fabs(token->value.number) > 9007199254740991.0 ) )
{
token->type = T_STRING;
strbuf_reset(json->tmp);
for (; json->ptr != endptr; json->ptr++ ) {
strbuf_append_char_unsafe(json->tmp, json->ptr[0]);
}
token->value.string = strbuf_string(json->tmp, &token->string_len);
return;
}
double类型有效位是16位,
当用double类型表示的数超过16位时,为了输出正确的值,可以转换为string类型输出
1万+

被折叠的 条评论
为什么被折叠?



