Thanks for using MS Q&A platform and posting your query.
I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to accept the answer .
Ask: I am getting below error in Data flow library function, parseDouble:
Cannot evaluate constant value with this type\n\t
Below is the Data flow library function:
toDecimal(concat(toString(toLong(substring(i1, 1, i2))), '.', toString(toLong(substring(i1, i2 + 1, i3)))), i2 + i3, i3)
i1 is type string, i2 and i3 is of type integer
The calling Data Flow is:
parseDouble(trim(substring(value, 236, 18)), 9, 9) where i2=9 and i3=9
The function works fine if I hard code i2 and i3 in it.
toDecimal(concat(toString(toLong(substring(i1, 1, 9))), '.', toString(toLong(substring(i1, 10, 9)))), 18, 9)
**Solution:**On further investigation, it looks like the precision and scalar arguments toDecimal function is causing an issue. If I remove them then it works though the resultant number has only 2 decimal places. Below works:
toDecimal(
concat(
toString(toLong(substring(i1, 1, toInteger(i2)))),
'.',
toString(toLong(substring(i1, toInteger(i2) + 1, toInteger(i3))))
)
)
If I add them back (snippet below) then I get the same error.
toDecimal(
concat(
toString(toLong(substring(i1, 1, toInteger(i2)))),
'.',
toString(toLong(substring(i1, toInteger(i2) + 1, toInteger(i3))))
),
toInteger(i2) + toInteger(i3),
toInteger(i3)
)
Please note that the input to the function remains same for both.
parseDouble(trim(substring(value, 236, 18)), 9, 9)
It works when I pass constant values for precision and scalar arguments as below:
toDecimal(
concat(
toString(toLong(substring(i1, 1, toInteger(i2)))),
'.',
toString(toLong(substring(i1, toInteger(i2) + 1, toInteger(i3))))
),
9 + 9,
9
)
If I missed anything please let me know and I'd be happy to add it to my answer, or feel free to comment below with any additional information.
If you have any other questions, please let me know. Thank you again for your time and patience throughout this issue.
Please don’t forget to Accept Answer
and Yes
for "was this answer helpful" wherever the information provided helps you, this can be beneficial to other community members.