How to check if a string can be parsed to decimal?

0
I am looking at a string attribute that holds alpha-numeric values. Before the parse operation, I need to check if the string holds values that can be parsed. For example the string “5.6” should be parsed  but the string  “A” should not be. How can I identify if a string holds a value that can be parsed?
asked
3 answers
1

You can check with regex if the string only consists of numerals or you can do the parse and catch the exception it will throw (see docs on error handling)

answered
0

Hi Djeerej!

The parseDecimal function can receive a default value that will be returned if the value cannot be parsed maybe you can use it.

For more info: https://docs.mendix.com/refguide/parse-and-format-decimal-function-calls/#2-parsedecimal 

answered
0

You can first check the string value if it contains “.”(decimal) by find() or contain() string function according to your requirement, if yes then parse it else skip.

Refer-String Function Calls | Mendix Documentation

Other way what stephan already suggested- do the parse and catch the exception it will throw (see docs on error handling)

answered