In the 3rd tip I have described nuisance with casting to integer value. This time we will look at really large numbers and their formatting. In addition I will mention scientific notation. All these topic are around number format used by DataWeave engine. So let’s see what the problem looks like.

## Problem

This problem may not be obvious. What is more it may not happen for a long, very long time. Would you consider in your **XML/json** document value **4.5E7** a correct number? Although in json schema exponential (scientific) notation is considered as a correct one, clients may not well handle it if they are not aware of such possible notation. In XML decimal type marks this notation as invalid one.

You may ask so what is the problem here mate. The answer is easy. DataWeave uses one internal data type to represent a number/integer. In some arithmetic operation like multiplication/division DataWeave engine will try to preserve precision lose and instead of typical decimal number we will receive number in exponential notation. Like in the example below:

<br /> %dw 2.0<br /> output application/dw<br /> ---<br /> {<br /> total: (payload.price * payload.quantity) * (1-payload.discount/100)<br /> }<br />

If we try to transform following input value

<br /> {<br /> "quantity": 50,<br /> "price": 1000000,<br /> "discount": 10<br /> }<br />

DataWeave will produce something like this:

<br /> {<br /> total: 4.5E7<br /> }<br />

However I do not like the returned value. I would like to have a standard notation as I later on transform this to XML and this is not a correct value. Here is the expected outcome:

<br /> {<br /> total: 45000000<br /> }<br />

This problem will not occur if the number will be less than** 10 000 000**.

## Solution

In order to fix this we need to cast value to string and then to number.

</p> <p>%dw 2.0<br /> output application/json<br /> ---<br /> {<br /> total: ((payload.price * payload.quantity) * (1-payload.discount/100)) as String as Number<br /> }</p> <p>

As you can see we need to cast two times. The most important is casting to **String** as then our number is converted to standard notation. This works for** DataWeave 2**. For DataWeave 1 we need to format string as well, like below:

<br /> %dw 1.0<br /> %output application/json<br /> ---<br /> {<br /> total: ((payload.price * payload.quantity) * (1-payload.discount/100)) as :string {format: "#"} as :number<br /> }<br />

After I have cast exponential number to a string I have applied **format**. For both versions next cast as number is necessary when we want to avoid quotation marks around the string. How format works was quite nicely described in the following article.

## Summary

In order to avoid sending numbers as exponential ones, casting to string and number is necessary. This problem occurs due to the fact that DataWeave is using one data type for storing different types of numbers and for preserving number precision.

Thank you, this is good info. I did actually come across this scenario recently and found the output representation a bit odd. Now I know how to make my code more readable.