我如何將最後一列的數字舍入到小數點後兩位?如何將最後一列的數字舍入到使用JQ的小數點後兩位小數?
我有JSON:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 9,
"successful": 9,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 2.575364,
"hits": [
{
"_index": "my-2017-08",
"_type": "log",
"_id": "AV5V8l0oDDWj-VP3YnCw",
"_score": 2.575364,
"_source": {
"acb": {
"version": 1,
"id": "7",
"owner": "pc",
"item": {
"name": "Account Average Latency",
"short_name": "Generate",
"description": "Generate of last month"
},
"service": "gsm"
},
"@timestamp": "2017-07-31T22:00:00.000Z",
"value": 210.08691986891395
}
},
{
"_index": "my-2017-08",
"_type": "log",
"_id": "AV5V8lbE28ShqBNuBl60",
"_score": 2.575364,
"_source": {
"acb": {
"version": 1,
"id": "5",
"owner": "pc",
"item": {
"name": "Profile Average Latency",
"short_name": "Profile",
"description": "Profile average latency of last month"
},
"service": "gsm"
},
"@timestamp": "2017-07-31T22:00:00.000Z",
"value": 370.20963260148716
}
}
]
}
}
我用JQ獲得CSV數據:
["Name","Description","Result"],(.hits.hits[]._source | [.acb.item.name,.acb.item.description,.value])|@csv
我看到的結果:
"Name","Description","Result"
"Account Average Latency","Generate of last month",210.08691986891395
"Profile Average Latency","Profile average latency of last month",370.20963260148716
我210.08691986891395和370.20963260148716但我想要210.09和370.21
感謝您的回答。但我檢查了這一點,我看到一個錯誤: jq:錯誤:round/0未定義在,第1行: def roundit:。* 100.0 | round/100.0; [「名稱」,「描述」,「結果」],(.hits.hits [] ._ source | [.acb.item.name,.acb.item.description,.value | roundit])| @csv jq:1編譯錯誤 是的,我正在使用Linux(jq版本1.5) –
是的,似乎'round'也不適合你。但我們也可以用'floor'來實現。不完全一樣,但會足夠接近。 –