简体   繁体   English

在Dataweave中将字符串转换为布尔值,十进制,数字和整数

[英]Convert string to boolean, decimal, number and integer in Dataweave

I am looking to convert the string fields from a CSV input file into specific datatypes, namely Boolean, decimal, number and integers. 我希望将CSV输入文件中的字符串字段转换为特定的数据类型,即布尔,十进制,数字和整数。

When I do this in Dataweave I am receiving a message saying that dataweave cannot convert a string to eg integer. 当我在Dataweave中执行此操作时,我收到一条消息,提示dataweave无法将字符串转换为例如整数。

This is an example of one of the conversions: 这是转换之一的示例:

Rate: payload01."rate" as :number,

How can I do the conversions? 我如何进行转换?

String -> Integer
String -> Decimal
String -> Boolean
String -> number

I'm using Anypoint Studio 6.2 and Mule 3.8.1 我正在使用Anypoint Studio 6.2和Mule 3.8.1

Thanks 谢谢

For string to Decimal,Integer and number use: Rate: payload01."rate" as :number 对于要转换为十进制,整数和数字的字符串,请使用:比率:payload01。“ rate”为:number

Because there is only one NUMBER type that supports both floating point and integer numbers. 因为只有一种NUMBER类型同时支持浮点数和整数。 There is no loss of precision in any operation, the engine always stores the data in the most performant way that doesn't compromise precision. 在任何操作中都不会损失精度,引擎始终以不影响精度的最高性能方式存储数据。

For Boolean Type, you can follow this,as mentioned in Mulesoft Forum. 对于布尔类型,您可以按照Mulesoft论坛中所述进行操作。 https://forums.mulesoft.com/questions/40071/dataweave-convert-value-to-boolean-type.html https://forums.mulesoft.com/questions/40071/dataweave-convert-value-to-boolean-type.html

For the errors your getting,please check the datatype of the input field "Rate". 对于您得到的错误,请检查输入字段“ Rate”的数据类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM