|55h||MT$FBGN||convert floating point to string|
|Input||A register - field width of output string.
B register - number of decimal places (disabled if negative).
X register - address of output buffer.
|Output||B register - length of the output string.|
Converts floating-point accumulator to numeric ascii text in general format, ie. in whichever of the above three formats is the most suitable for the given number and field width.
The output string will be in integer format if the number is a floating-point integer, otherwise decimal format. If the field width is not sufficient for the above, the number is output in scientific format rounded to as many decimal places as can be accommodated. A field width of 7 is sufficient to convert any floating-point number without returning an error, though severe truncation of the mantissa may result.
Fixing the number of decimal places is optional, and is disabled if B is negative (bit 7 set). In this case the number of decimal places will be set equal to the number of significant digits to the right of the decimal point. If B is positive, then it contains the number of decimal places to be fixed.
Returns the output string (not zero-terminated) at the address given by X on entry, with the length of the string in B. X should be preserved before calling, as there is no pointer to the output string on exit.
The following code will convert the value in the
accumulator to a text
string in a field width of 16:
LDX #STRING_BUF LDAB #80h ;disable fixed decimal places LDAA #16 ;field width in A OS MT$FBGN STRING_BUF: DS 16If the accumulator contained e.g. 172.65, STRING_BUF will now contain the string "172.65" and the B register will contain 6. Note that the format in this case is decimal as this can be fitted into the given width. Further examples of the output strings corresponding to various floating-point values follow:
Accumulator Width Dec. Places Output String 0 1 Disabled 0 3000000.078 20 Disabled 3000000.078 -0.00005 8 Disabled -0.00005 -0.00005 7 Disabled -5E-05 123456789012000000 16 Disabled 1.2345678901E+17 0.00123456789012 16 Disabled 0.00123456789012 0.99999999 6 Disabled 1E+00 -0.9 6 Disabled -0.9 -0.99999999 7 Disabled -1E+00 7000000 4 Disabled Error 7000000 7 Disabled 7000000 5000 10 3 5000.000 234.77 20 12 234.770000000000
|Errors||250 - output string too long for field width or greater than maximum work buffer length of 34 (NUM to STR Error)|