Knowledge Base

Specifies floating point data as an argument to a supporting hash function.

Formatter Prototype
f(
Source,
FieldWidth,
Decimals,
Style )
ParameterOptionDescription
SourcemandatoryQuite simply, this is what to print
FieldWidthoptionalNumber 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.
DecimalsoptionalMaximum number of decimal places to print.  Range is 0 thru 7, default is 7.  This value cannot be specified without the FieldWidth value.
Styleoptional“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

FormMeaningExample
=wContents of the W register#HMI Print(f(=w))
=qContents of the Q register#HMI Print(f(=q))
ConstantContents of an EQUated constant. This can be plain EQUfEQU or #EQUFoo fEQU 56.78...#HMI Print(f(Foo))
Any valid floating point numberAn immediate numeric value#HMI Print(f(3.1415926))#HMI Print("3.1415926")
*LabelContents of a float in RAMfTemperature defFLOAT...#HMI Print(f(*Temperature))
index/jndex modifiers

RAM variable references can also have index/jndex modifiers

FormWhat is sourcedExample code
*+ffWhatever is in RAM (float) variable ff, with IasJ: applied#HMI Print(f(*+fCounter)) ;Force indexing
*-ffWhatever is in RAM (float) variable ff, with NoJ: applied#HMI Print(f(*-fCounter)) ;Inhibit jndexing

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 codeResult (the single quotes are NOT printed)Notes
#HMI Print(f(1.23456))' 1.23456'Defaults to 9, 9
#HMI Print(f(1.23456, 9))' 1.23456'Defaults to 9, 9 because FieldWidth and Decimals must be both present to affect the outcome (all or nothing)
#HMI Print(f(1.23456, 5, 3))'1.235'Note rounding
#HMI Print(f(-1.23456, 5, 3))'-1.23'Limited by f character positions
#HMI Print(f(-1.23456, 5, 9))' -1.235'Limited by 3 decimal places; padded left with spaces
#HMI Print(f(12.3456, 5, 3))'12.35' 
#HMI Print(f(123.456, 5, 3))'123.4' 
#HMI Print(f(1234.56, 5, 3))' 1235'Decimal point suppressed
#HMI Print(f(12345.6, 5, 3))'12346' 
#HMI Print(f(123456, 5, 3))'+++++'Overflow: result can’t fit in field
#HMI Print(f(-12345.6, 5, 3))'-----'Underflow (negative overflow)
#HMI Print(f(0.123456, 5, 3))'0.123'Leading “0.” is displayed
#HMI Print(f(-0.123456, 5, 3))'-0.12' 
#HMI Print(f(-0.00012345, 5, 3))'-0.000'Take care with small numbers!