toString Method

Class: Number

Description

This method formats a number value as a string.

Syntax

NumberObject.toString(Number decimal,String formatMask)

Parameters

decimal

The number of decimal precision to display in the string.

formatMask

An editing mask to control the output:

 

Position

Interpretation

 

1

Decimal representation. Use the "." symbol for most applications.

 

2

Thousands separator. Use the "," symbol for most applications. The character "9" indicates no thousand separator.

 

3

Display of numbers. Review M $FN functionality to understand the values (+-,T).

  • L or space - Represents the negative number with a leading sign. Positive numbers have neither sign nor space.

  • T - Represents the number with a trailing rather than leading sign. Positive numbers have a trailing space.

  • P - Represents negative values in parentheses. Positive values have a space on either side.

  • - - Suppresses the "-" on negative values.

  • + - Forces the "+" in front of positive values.

 

4

Character to append to the front of the string such as $. If " " (space), no character is appended.

 

Example

The following code converts 123.45678 to string $123.457:

type Number zzz

w zzz.toString("3",".,T$")

Returns

A String.

When Became Available

Profile v7.0

Example

// A positive and a negative value to demonstrate behavior

type Number POS = 12345678.9876

type Number NEG = -98765432.1234

 

Type String P1 = POS.toString(2,",9P#")   // "# 12345678,99 "

Type String N1 = NEG.toString(2,",9P#")   // "#(98765432,12)"

Type String P2 = POS.toString(2,",.T$")   // "$12.345.678,99 "

Type String N2 = NEG.toString(2,",.T$")   // "$98.765.432,12-"

Type String P3 = POS.toString(2,". +Y")   // "Y+12 345 678.99"

Type String N3 = NEG.toString(2,". +Y")   // "Y-98 765 432.12"

Type String P4 = POS.toString(2,".,-$")   // "$12,345,678.99"

Type String N4 = NEG.toString(2,".,-$")   // "$98,765,432.12"

 

Type String PI = POS.toString(2,".,  1")  // "1,23,45,678,99"

Type String NI = NEG.toString(2,".,  1")  // "-98,765,432.12"