Dataweave始终输出带有两位小数的JSON编号 [英] Dataweave Always output JSON number with two decimal places
本文介绍了Dataweave始终输出带有两位小数的JSON编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Dataweave中通过xml输入了以下数字.
I've got the following number coming through via xml in Dataweave.
<b:AmountValue>180.90</b:AmountValue>
使用Dataweave,我试图输出一个带有两个小数位(代表货币)的json编号.
Using Dataweave I am trying to output a corresponding json number with two decimal places (to represent currency).
这是我的Dataweave表达式的样子...
Here is what my Dataweave expression looks like...
amount: $.AmountValue as :number as :string {format: ".00"} as :number
输出json丢失尾随零.
The output json is losing the trailing zero.
i.e. "amount":180.9
如何将Dataweave表达式更改为始终有两个小数位?
How can I change my Dataweave expression to always have two decimal places?
或者也许我误解了json数字类型?
Or perhaps I'm misunderstanding the json number type?
谢谢
推荐答案
如果可以将金额作为字符串使用,则删除最后一个as :number
remote the last as :number
if you can live with amount being a string
amount: $.AmountValue as :number as :string {format: ".00"}
这篇关于Dataweave始终输出带有两位小数的JSON编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文