dm-script

How can I convert a string to a number in DM script for flag values?


I'm trying to read a configuration file in DM script and use its content as flags. For instance, the function TagGroup DLGCreateChoice( TagGroup &items, number value ) uses a number to pre-select a choice, but the configuration file returns strings.

Instead of using an if clause like below, I would prefer a more straightforward method to convert a string to a number:

// Some code to get the string value, stored in flag_string
if (flag_string == "1") flag_value = 1;

Questions:

Any guidance or examples would be greatly appreciated!


Solution

  • You are looking for the command val() as in:

    string str = "1234.53345345"
    number num = val(str)
    Result("\n '"+str+"' evaluates to:"+num+ " ( Formatted:"+Format(num,"%20.5f")+" )" )