pui.editCode( number, editCode )





pui.editCode( number, editCode, [length], [decPos], [curSym], [options] )

This JavaScript function can be used to format numbers when placing them into a string. It implements edit codes like those commonly found in RPG and DDS programming techniques.

Required parameters:

  • number - a JavaScript number (or numeric expression) that is to be formatted

  • editCode - character representing an edit code. The following table describes the possible edit codes:


Edit Code Description

No Sign

Cr Sign

-Sign(R)

-Sign(L)

Edit Code Description

No Sign

Cr Sign

-Sign(R)

-Sign(L)

Commas and zero balances

1

A

J

N

Commas

2

B

K

O

Zero Balances

3

C

L

P

No commas or zero balances

4

D

M

Q

Hexadecimal F/D Sign

X







Date edit

Y







Suppress leading zeroes

Z









Optional Parameters:

  • Length - the number of digits of the formatted number.  If not supplied, the number of significant digits in the number parameter will be used.

  • DecPos - the number of decimal places in the formatted number.  If not supplied, zero will be assumed.

  • CurSym - a currency symbol that will be added to the output.  If not supplied, no symbol is added.

  • Options - a JavaScript object with additional formatting options, described below.

Options Object:

  • dateEdit - date (edit code Y) style for 8-digit numbers.  Can be *ymd for xxxx/xx/xx.  If not specified, xx/xx/xxxx is used.

  • dateEditSeparator - separator used in date (edit code Y) output.  If not specified, the / character is used as a separator.

  • decimalEdit - Editing control for decimal numbers.  Possible values are follow:

    • "." - use period for decimal separator, do not show a leading zero on fractions (default)

    • "," - use comma for decimal separator, do not show a leading zero on fractions

    • "0." - use period for decimal separator, show a leading zero before fractions

    • "0," - use a comma for decimal separator, show a zero before fractions

Examples:

var val0 = 1000; pui.editCode(val0, "J"); // "1,000 " pui.editCode(val0, "J", "$"); // "$1,000 " pui.editCode(val0, "J", 9, 2); // " 1,000.00 " pui.editCode(val0, "J", 9, 2, "$"); // " $1,000.00 " pui.editCode(val0, "J", 9, 2, { decimalEdit: "," }); // " 1.000,00 " var val1 = "-25"; pui.editCode(val1, "1", 9, 2); // " 25.00" pui.editCode(val1, "A", 9, 2); // " 25.00CR" pui.editCode(val1, "J", 9, 2); // " 25.00-" pui.editCode(val1, "N", 9, 2); // " -25.00" var val2 = 0.5; pui.editCode(val2, "P"); // " 0.5" pui.editCode(val2, "P", 9, 2, { decimalEdit: "." }); // " .50" pui.editCode(val2, "P", 9, 2, { decimalEdit: "," }); // " ,50" pui.editCode(val2, "P", 9, 2, { decimalEdit: "0." }); // " 0.50" pui.editCode(val2, "P", 9, 2, { decimalEdit: "0," }); // " 0,50"







This function first appeared in Profound UI 5.13.0