如何防止jq自动将double转换为int? [英] How to prevent jq from automatically converting double to int?
问题描述
我有input_file
:
{"hi":48.0, "yep":48.123}
我运行这个
jq . < input_file > output_file
cat output_file
我的输出:
{
"yep": 48.123,
"hi": 48
}
我希望输出为
{
"yep": 48.123,
"hi": 48.0
}
如何防止jq将我的双精度值自动转换为int?
How do I prevent jq from automatically converting my double values to an int?
推荐答案
jq将数字解析为C个双精度数.然后,将其格式化为数字.这种转换有两种损失方式:a)有很多方式可以表示相同的数字,但是jq只使用一种表示,否则没有其他选择,b)C的双精度具有有限的精度.
jq parses numbers into C doubles. It then formats them back as numbers. This conversion is lossy in two ways: a) there are many ways to represent the same number, but jq uses only one and has no options to do otherwise, b) C doubles have finite precision.
关于这两个问题,jq存在一些问题.可能的解决方案是采用bignum/bigfloat方法,并保持原始数字字符串保留未修改的数字(原样; jq将所有数据视为写时复制).但这还没有实现.
There are issues open against jq about both problems. The likely solution will be to adopt a bignum/bigfloat approach, and to keep the original number string for numbers passed through unmodified (as it were; jq treats all data as copy-on-write). But that isn't implemented yet.
这篇关于如何防止jq自动将double转换为int?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!