![](/img/trans.png)
[英]How to keep trailing 0s while converting a string to BigDecimal without exponent
[英]How to avoid exponent while converting a string to number in DataWeave 1.0
我正在將存儲在有效負載中的字符串“ 0.0000000”轉換為Data Weave語言1.0中的數字
我嘗試了payload.Amount為:number
%dw 1.0
%output application/json
---
{
Amount: payload.Amount as :number when payload.Amount != null
}
我期望最終輸出為0.0000000,但我得到0E-7
我認為您的期望是不正確的。 根據RFC 4627,0E -7是JSON的完全有效數字。 任何正確的解析器都應正確處理此有效數字。 與其他語言一樣,數字在JSON中沒有格式化屬性。 僅當它們轉換為字符串或從字符串轉換時,才可以應用格式。 由於這些原因,您不能告訴DataWeave使用特定格式。
現在,如果您遇到使0E-7成為問題的特定問題,請更新說明以添加更多細節。
如果可以設置固定的小數位數,則可行的一種替代方法是采用https://help.mulesoft.com/s/article/How-to-force-DataWeave-to-return-Long-數
例
%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:string {format:“ 0.0000000”}
此處討論更多示例
https://help.mulesoft.com/s/article/How-to-format-numbers-in-DataWeave
嘗試像
as:number as:number {格式:“#。#######”}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.