在 DataWeave 1.0 中将字符串转换为数字时如何避免指数

我正在将存储在有效负载中的字符串“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


MYYA
浏览 98回答 3
3回答

Helenr

我认为你的期望是不正确的。根据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}

湖上湖

尝试像as :number as :number {格式: "#.#######"}

LEATH

您可能想要指定精度。就像是as :number as :string {格式:“0.0000000”}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java