Hi @Peruka, Sikander reddy
Welcome to Microsoft Q&A platform.
Thank you for reaching out and providing detailed information about the issue you're encountering with the toDecimal
function in Azure Data Factory (ADF) or Azure Synapse Analytics.
Understanding the Issue:
When converting the string '252567552' using toDecimal(trim(COST))
, the function returns NULL
instead of the expected 2525675.52
. This discrepancy arises because, by default, the toDecimal
function in ADF assumes a precision of 10 and a scale of 2 (decimal(10,2)
). In this context:
- Precision (10): Total number of digits allowed, both before and after the decimal point.
- Scale (2): Number of digits allowed after the decimal point.
The number '252567552' exceeds the default precision, leading to a NULL
result upon conversion.
Proposed solution:
To correctly format your numbers while ensuring that only necessary values are adjusted, you can use a conditional expression in your Derived Column transformation:
iif(length(COST) > 8, toDecimal(toInteger(COST) / 100, 12, 2), toDecimal(COST, 12, 2))
- For numbers longer than 8 digits, it assumes the last two digits should be after the decimal and divides by 100.
- For shorter numbers, it keeps them unchanged.
Expected Output:
This should resolve the issue while keeping other numbers accurate. Let me know if you need further clarification!
Hope this helps. Do let us know if you any further queries.
If this answers your query, do click Accept Answer
and Yes
for was this answer helpful. And, if you have any further query do let us know.