format_number

format_number converts a number to a string. The decimal character and the thousands separator can be specified.

string = format_number(number)
string = format_number(number, nDecimals)
string = format_number(number, nDecimals, ssSeparators)

Return Value

string is a string matrix.

Parameters

number

number is a scalar number of a matrix of numbers.

nDecimals

nDecimals is a number in the range 0 to 20 and sets the number of decimal points. Default value is 4.

If nDecimals is negative (-1 to -20) the “g”-Format is used, see sprintf. -6 is equal to %g.

ssSeparator

ssSeparator is a string with one or two characters. The first character is the decimal character. The second character sets the thousands separator. Both characters can be set in the windows registry: Settings\DecimalSeparator and Settings\ThousandsSeparator. Default value id “.,”.

Example

* format_number(1234)
  1234.0000
* format_number(1234, 2, ".,")
  1,234.00
* format_number(1234, 2, ",.")
  1.234,00
* format_number(1234, -2, ".,")
  1.2e+3
* format_number(1234, -6, ".,")
  1,234
* format_number(1234567, 0, ". ")
  1 234 567

History

Version Description
R2012 (5.40.0) New.

id-589650