## `stringlib::formatf` -- Convert a floating point number to a string

#### Introduction

`stringlib::formatf(`f, d`)` converts the floating point number `f` into a string after rounding it to `d` digits after the decimal point.

#### Call(s)

`stringlib::formatf(f, digits <, strlength>)`

#### Parameters

`f` | - | floating point number
`digits` | - | integer which determines the precision of the number
`strlength` | - | integer which determines the length of the returned string

#### Returns

`stringlib::formatf` returns a string.

#### Related Functions

`stringlib::format`

#### Details

- If `d` is a positive integer, a rounded fixed-point representation with `d` digits after the decimal point is returned. If `d` is zero, then a rounded fixed-point representation with one zero after the decimal point is returned. If `d` is negative, then `f` is rounded to `-d` digits before the decimal point and a fixed-point representation with one zero after the decimal point is returned.
- The representation of a negative number starts with the sign and no additional spaces. The representation of a nonnegative number starts with a single space character.
- If a third argument is specified, then the string returned consists of exactly `strlength` characters. If the converted number `f` requires less room, then it is padded on the left with spaces. If the converted number `f` requires more room, then the last characters are truncated.

#### Example 1

Convert the number `123.456` with two characters after the point into a string:

    >> stringlib::formatf(123.456, 2)

                                     " 123.46"

The same for `-123.456`:

    >> stringlib::formatf(-123.456, 2)

                                     "-123.46"

Convert the number `123.456` with two characters after the point into a string of the length `10`:

    >> stringlib::formatf(123.456, 2, 10)

                                   "    123.46"

If the string should only have the length `3`, the whole number does not fit into the string:

    >> stringlib::formatf(123.456, 2, 3)

                                       " 12"

Rounding to no number after point:

    >> stringlib::formatf(123.456, 0)

                                     " 123.0"

Rounding to one number in front of point:

    >> stringlib::formatf(123.456, -1)

                                     " 120.0"

#### Changes

- used to be called `string::formatf`

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000