Forum Discussion
Decimal Parameters in User Defined functions (UDF)
- 1 month ago
Hi ZvikaBK2801,
Thank you for reaching out to Microsoft Fabric Community.
Thank you avinash_7995 for the prompt response.
This is expected. In a DAX UDF, the decimal type is a fixed decimal (currency) type that only keeps 4 decimal places, so 0.0045 / 230 rounds to 0.
For calculations that require more than 4 decimal places, use the Double type instead, as it is designed for higher precision values.
Thanks and regards,
Anjan Kumar Chippa
- 1 month ago
Hi, yes the solution had been provided thanks. I'm now using Double for all my non integer UDF parameters. I also notified the couple PBI local user groups about this issue.
Thanks for sharing. However, I don't think this is an inherent limitation of the "Decimal" data type. A decimal value like "0.0045 / 230" equals approximately "0.0000195652", which should not become zero simply because it's stored as a decimal.
If the result is being truncated after four decimal places, it's more likely due to the UDF implementation, a fixed decimal scale (for example, "DECIMAL(...,4)"), or how the result is being displayed, rather than the "Decimal" type itself.
In general, "Decimal" is preferred for precise decimal calculations (such as financial data), while "Double" is better suited for scientific calculations where a larger range is needed and small floating-point rounding errors are acceptable.
- ZvikaBK28011 month agoRegular Visitor
Hi,
It's not an issue of how the UDF outcome is displayed, nor is it any delibarate or indeliberate trancation under user repsponsibility. Why don't you try it out for yourseft insteat of thinkg how PBI should work.- v-achippa1 month agoCommunity Support
Hi ZvikaBK2801,
Thank you for reaching out to Microsoft Fabric Community.
Thank you avinash_7995 for the prompt response.
This is expected. In a DAX UDF, the decimal type is a fixed decimal (currency) type that only keeps 4 decimal places, so 0.0045 / 230 rounds to 0.
For calculations that require more than 4 decimal places, use the Double type instead, as it is designed for higher precision values.
Thanks and regards,
Anjan Kumar Chippa
- v-achippa1 month agoCommunity Support
Hi ZvikaBK2801,
As we haven’t heard back from you, we wanted to kindly follow up to check if the solution I have provided for the issue worked? or let us know if you need any further assistance.
Thanks and regards,
Anjan Kumar Chippa