我正在將存儲在有效負載中的字符串“0.0000000”轉換為 Data Weave 語言 1.0 中的數字我嘗試了有效負載。金額為:number%dw 1.0%output application/json---{ Amount: payload.Amount as :number when payload.Amount != null}我預計最終輸出為0.0000000但我得到0E-7
3 回答

Helenr
TA貢獻1780條經驗 獲得超4個贊
我認為你的期望是不正確的。根據RFC 4627?,0E-7 是一個完全有效的 JSON 數字。任何正確的解析器都應該正確處理這個有效數字。與其他語言一樣,數字在 JSON 中沒有格式屬性。只有當它們與字符串相互轉換時,才能應用格式。由于這些原因,您無法告訴 DataWeave 使用特定的格式。
例子
%dw 1.0
%output application/json
%function withZeroes(x)? x as :string { format: "#.####" } as :number
---
{
? Amount: withZeroes(0E-7),
? Amount2: withZeroes(0.000),
? Amount3: withZeroes(0.0001),
? Amount4: withZeroes(0.00001)
}
輸出:
{
? "Amount": 0,
? "Amount2": 0,
? "Amount3": 0.0001,
? "Amount4": 0
}
添加回答
舉報
0/150
提交
取消