In MuleSoft DataWeave, when converting a decimal number to a string using the format "(0.00)" as String {format: "0.0000000"}. Instead of getting a decimal separated with a decimal point "0.0000000", you get a decimal separated with a comma "0,0000000". This would subsequently impact follow-on flows when this String value is converted back to a number and with the comma separator, as shown in the below example.
ERROR 2023-04-05 09:13:56,739 [[MuleRuntime].uber.01: [testdwissue].testdwissueFlow.CPU_INTENSIVE @da052a5] [processor: ; event: 4f080140-d381-11ed-ab5f-fe5c682c08df] org.mule.runtime.core.internal.exception.OnErrorPropagateHandler:
********************************************************************************
Message : "org.mule.weave.v2.exception.InvalidNumberException: Cannot coerce String (0,372970) to Number
3| (nsv * rate) as String {format: "0.000000"} as Number
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Trace:
at anonymous::calcNSV (line: 3, column: 3)
at anonymous::main (line: 5, column: 1)
" evaluating expression: "output application/json
fun calcNSV(nsv, rate) =
(nsv * rate) as String {format: "0.000000"} as Number
---
calcNSV(12.206284506290 default 0, 0.03055556 default 0)".
Element : testdwissueFlow/processors/0 @ testdwissue:testdwissue.xml:13 (Transform Message)
Element DSL : <ee:transform doc:name="Transform Message" doc:id="f8fcc7f6-2699-462a-8136-d3d5b7fe0912">
<ee:message>
<ee:set-payload><![CDATA[
output application/json
fun calcNSV(nsv, rate) =
(nsv * rate) as String {format: "0.000000"} as Number
---
calcNSV(12.206284506290 default 0, 0.03055556 default 0)
]]></ee:set-payload>
</ee:message>
</ee:transform>
Error type : MULE:EXPRESSION
FlowStack : at testdwissueFlow(testdwissueFlow/processors/0 @ testdwissue:testdwissue.xml:13 (Transform Message))
Payload : null
Payload Type : null
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.runtime.api.el.ExpressionExecutionException: org.mule.weave.v2.exception.InvalidNumberException: Cannot coerce String (0,372970) to Number
3| (nsv * rate) as String {format: "0.000000"} as Number
When receiving the error in MuleSoft's DataWeave "Cannot coerce String to Number", a locale is not specified if the application is being run on a machine that uses a regional setup and the "," is used as a decimal separator.
In DataWeave, to format the decimal numbers with a "." separator as in the U.S., you will need to specify the locale as detailed in this document.
For example, this script will output "0,3400":
- 0.34 as String {format: "0.0000", locale: "ES"}
While this script will output "0.3400":
- 0.34 as String {format: "0.0000", locale: "US"}
001123351

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.