15
Views
1
Comments
Solved by AI
Text To Decimal outputs a 0
Question

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)

2023-12-26 10-35-28
OutSystems Neo
Staff
Solution by AI
AI Generated

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.

Here are some suggestions to resolve this issue:

  1. 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:

    Replace(InputText, ",", "")
    

    Then pass the cleaned-up text to the TextToDecimal() function.

  2. 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:

    Replace(InputText, ",", ".")
    

    After replacing, use the TextToDecimal() function.

  3. 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.

Let me know if this doesn't resolve your problem!

This answer was AI-generated. Please read it carefully and use the forums for clarifications
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.