Previous Page Next Page Contents

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

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




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000