Format numbers as character strings
This example describes the standard method to transform numbers into strings and how FlowHeater can be used to sidestep the standard format options of the WRITE Adapter.
What we want to achieve
Here we will use the TestData Adapter to generate random test data and the TextFile Adapter to provide the output or report. 1000 dynamic test data records will be created to serve as input to the TextFile Adapter. By the same token import/export text files (CSV, TXT, ASCII, ASC) could be specially formatted for databases. Specific adapters for the import from or export to databases are available in FlowHeater, these include Microsoft Access, MySQL, MS SQL Server, Oracle and ODBC.
You will find this example in the file Examples\EN\Common\format_number.fhd. All examples are included in the ZIP archive of FlowHeater, which is available for download here.
After opening the example Definition in FlowHeater, your screen should appear similar to the screenshot on the right. You will notice there are three Format Heaters and a collection of Clone Heaters. The sole purpose of the Clone Heaters is to make the layout of the Definition visually clearer. Our main focus here is on the Format Heaters. First inspect for yourself the property settings of the Format Heaters, by a double click on each heater icon in turn to open its properties popup window.
Experiment by running the Definition using the execute button (circled in red). FlowHeater’s Test and Execute popup window opens. Execute the definition leaving the default settings as they are and inspect the data output. The text file viewer built into the TextFile Adapter will display the 1000 test data lines that are generated. Please note that in this case no actual file is changed or written to disk (apart from a temporary file). Only when you first uncheck the "test mode" option in the Test and Execute window will the text filename "format_number.txt" be written to the same directory as the Definition file.
Description of the output, or how does the data get formatted this way?
Note: When we talk about the data type or format of a field, we refer to the properties of the field in the WRITE Adapter (right side). In order to view the properties of a field it is only necessary to click on the field and the properties of that field is then shown at the bottom of the Adapter details. By standard the default locale is indicated. The locale in this example is set to German.
- int standard: This format comes as the standard setting of the WRITE Adapter. You can inspect the other settings using the Configurator of the WRITE Adapter.
- int without format: Here the field’s Format property is set to "0".
- int currency Dollar: Here a whole number (integer) is sent by the Format Heater that is interpreted as a currency value. The Format Heater is configured so that the number is preceded by a currency symbol, assumes 3 decimal places and uses a point as decimal separator character. The locale is "English (USA)". Please note that in this case the field data type must be set to STRING - otherwise FlowHeater would attempt to reconvert the already formatted number into a FlowHeater number.
- int currency Euro: Here the field data type would be set to "currency", the formatting is applied according to the standard settings of the WRITE Adapter.
- decimal standard: The same as "int standard", but with data type decimal.
- decimal without format: Here the field property Format is set to "0.000". Note that also 3 decimal places are created.
- decimal currency Danish Kroner: Here a number of type "decimal" is output by the Format Heater. The Format Heater is configured so that the locale "Danish (Denmark)" is employed. Please note that is this case the field data type is STRING, otherwise the same as the treatment of "currency Dollar".
- decimal currency Euro: This is again the standard format for the WRITE Adapter.
- Right justified using the Format Heater: A right-justified text string is output by the Format Heater. Note that in this case the field’s type must by set the STRING.
- Right justified using the TextFile Adapter: A right-justified text field is produced by the TextFile Adapter.