You can use toString in an OCL expression to convert a number to its text representation, with an optional numeric format string when you need a specific display form.
Syntax
number.toString()
number.toString('format')
number is the numeric value to convert. The optional format argument is a numeric format string that controls the resulting text.
Convert a number to text
Use toString() without an argument when you need the normal string representation of a number.
5.toString()
Use the result where an expression requires text, such as when building a text value from numeric data.
Format the converted value
Pass a format string when the text must follow a defined numeric pattern.
| Expression | Result | Use |
|---|---|---|
5.toString('00')
|
'05'
|
Produces at least two digits by adding a leading zero when needed. |
10.toString('X')
|
'A'
|
Converts the number to hexadecimal text using the X format.
|
For example, use '00' when a numeric value must be represented as a two-character text value:
5.toString('00')
The expression returns '05', not a number. Treat the result as text in subsequent expressions.
Choose expression formatting or view formatting
Use toString when the formatted value is part of the expression result. If you want to control how a value is presented in a ViewModel without changing the value used by the application, configure the ViewModel column formatting described in Documentation:Text formatting.
For the supported format-string syntax and additional numeric-format examples, see .NET standard numeric format strings.
