Floating point formatting function f()
Specifies floating point data as an argument to a supporting hash function.
Formatter Prototype
f(
Source,
FieldWidth,
Decimals,
Style )
Parameter | Option | Description |
---|---|---|
Source | mandatory | Quite simply, this is what to print |
FieldWidth | optional | Number of characters to print, including sign and decimal point. Leading spaces will be printed to ensure the number of displayed characters is always this width, unless the Style is set to "v". Range is 1 thru 9, default is 9. |
Decimals | optional | Maximum number of decimal places to print. Range is 0 thru 7, default is 7. This value cannot be specified without the FieldWidth value. |
Style | optional | "v" means "variable width". If the value is less than the specified width, then no leading spaces will be printed. Default is fixed width. |
The first argument specifies the data source. An optional pair of arguments specifies the format in terms of the number of characters total (FieldWidth
) and the number of digits after the decimal point (Decimals
). Unless both format arguments are present, the format defaults to FieldWidth=9
and Decimals=7
. If the result requires fewer than FieldWidth
character it will be padded to the left with spaces unless Style is set to "v".
Source specifiers
The following are the allowable source specifiers
Form | Meaning | Example |
| Contents of the W register |
|
| Contents of the Q register |
|
| Contents of an EQUated constant. This can be plain |
|
Any valid floating point number | An immediate numeric value |
|
| Contents of a float in RAM |
|
index/jndex modifiers
RAM variable references can also have index/jndex modifiers
Form | What is sourced | Example code |
| Whatever is in RAM (float) variable |
|
| Whatever is in RAM (float) variable |
|
NOTE: The modifier (+
or -
) must be after the asterisk. jndexing applies only to code running inside a MultiTrack task.
Format specifiers
The format arguments FieldWidth
and Decimals
specify how the number is to be displayed. The results are consistent with the older character LCD OBLCD_fDispW
instruction.
Examples (spaces shown as ^):
Example code | Result (the single quotes are NOT printed) | Notes |
|
| Defaults to 9, 9 |
|
| Defaults to 9, 9 because |
|
| Note rounding |
|
| Limited by f character positions |
|
| Limited by 3 decimal places; padded left with spaces |
|
| |
|
| |
|
| Decimal point suppressed |
|
| |
|
| Overflow: result can't fit in field |
|
| Underflow (negative overflow) |
|
| Leading " |
|
| |
|
| Take care with small numbers! |