Mule Dataweave格式:数字 [英] Mule Dataweave format :number

查看:78
本文介绍了Mule Dataweave格式:数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试解析字符串以使其倍增时遇到问题,这将是示例代码,它返回的是整数而不是类型:double any idea?

I'm having an issue trying to parse a string to double this would be a sample code, it's returning an integer instead of type :double any ideas?

{
    "data": "22" as :number { format: "##.##" }
}

推荐答案

只有这个对我有用;

%dw 1.0
%output application/json
---
{
    data: "22" as :number as :string {format: ".00"} as :number
}

从数字转换为字符串时,

format 似乎仅添加零. 如果"22"已经是一个数字,则无需进行第一次:number转换;

format only seems to add zeros when converting from a number to a string. If "22" would have already been a number you wouldn't need the first :number conversion;

data: 22 as :string {format: ".00"} as :number

后面的数字转换使其输出为浮点数.否则,您将得到一个字符串,该字符串根据主机的区域设置进行格式化.

The latter number conversion makes it output as a float. Otherwise you would get a string, formatted according to the hosts locale.

当心.当改用%output text/json时,上述代码在某些情况下会生成 22.0 而不是 22.00 .

And beware. When using%output text/json instead, the above code will in some cases produces 22.0 instead of 22.00.

这篇关于Mule Dataweave格式:数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆