我想格式化十进制输入,以便在输出中获得特定数量的字符,小数点前 10 位数字和小数点后 4 位数字。我想用 0 值填充。
例如,如果我接受以下输入:
[
{
"field1": "875.45"
}
]
那么输出应该是:
[
{
"field1": "0000000875.4500"
}
]
您可以使用 modify-overwrite-beta 转换规范以及 [left/right]Pad 函数,例如
[
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"pieces": "=split('\\.',@(1,field1))",//separate expression by dot
//by using escape( \\ ) characters, since some characters are onsidered
//as special such as dot
"piece1": "=leftPad(@(1,pieces[0]), 10, '0')",
"piece2": "=rightPad(@(1,pieces[1]), 4, '0')",
"field1": "=concat(@(1,piece1),'.',@(1,piece2))"
}
}
},
{// get rid of the unnecessary attributes
"operation": "remove",
"spec": {
"*": {
"piece*": ""
}
}
}
]
网站上的演示 https://jolt-demo.appspot.com/ 是: