I am fetching a text value and converting it to decimal to match variable type, but using TextToDecimal() returns a 0 even if the text is in correct format (100.44 or 1,100.32)
The issue you're facing might be caused by the formatting of the text value you're trying to convert to a decimal. The TextToDecimal() function expects the text to use the default decimal separator (a dot .) and no commas as thousand separators. If your text input includes a comma (,), the function will fail to parse it correctly and will return 0.
TextToDecimal()
.
,
0
Here are some suggestions to resolve this issue:
Remove Thousand Separators: If your input text includes commas as thousand separators (e.g., 1,100.32), you can use the Replace() function to remove them before converting. For example:
1,100.32
Replace()
Replace(InputText, ",", "")
Then pass the cleaned-up text to the TextToDecimal() function.
Handle Comma as Decimal Separator: If your input uses a comma as a decimal separator (e.g., 100,44), first replace the comma with a dot to match the expected format:
100,44
Replace(InputText, ",", ".")
After replacing, use the TextToDecimal() function.
Combining Multiple Cases: You can apply both fixes together if needed:
TextToDecimal(Replace(Replace(InputText, ",", ""), ",", "."))
This first removes thousand separators and then adjusts the decimal separator.
For additional reference, you can check a similar issue where Regex Replace and formatting tricks were used to handle different decimal separators Decimal separator.
Regex Replace
Let me know if this doesn't resolve your problem!