Right-aligns an expression within a specified width, rounding to a specified number of fractional digits.
||The value that is to be right-aligned. It can be a numeric value, a string literal, the name of a variable, or any valid ObjectScript expression.
||The number of characters within which expression is to be right-aligned. A positive integer or an expression that evaluates to a positive integer.
||Optional The number of fractional digits. A positive integer or an expression that evaluates to a positive integer. Caché rounds or pads the number of fractional digits in expression to this value. If you specify decimal, Caché treats expression as a numeric.
recognizes the DecimalSeparator character for the current locale. It adds or deletes a DecimalSeparator character as needed. The DecimalSeparator character depends upon the locale; commonly it is either a period (.) for American-format locales, or a comma (,) for European-format locales. To determine the DecimalSeparator character for your locale, invoke the following method:
is used to format numbers with fractional digits: every number is given the same number of fractional digits, and the numbers are right-aligned so that the DecimalSeparator characters align in a column of numbers. $JUSTIFY
is especially useful for outputting formatted values using the WRITE
The value to be right-justified, and optionally expressed as a numeric with a specified number of fractional digits.
to a canonical number, it zero-pads or rounds this canonical number to decimal
number of fractional digits, then right-justifies the result, as described in width
does not recognize NumericGroupSeparator characters, currency symbols, multiple DecimalSeparator characters, or trailing plus or minus signs.
in which to right-justify the converted expression
. If width
is greater than the length of expression
(after numeric and fractional digit conversion), Caché right-justifies to width, left-padding as needed with blank spaces. If width
is less than the length of expression
(after numeric and fractional digit conversion), Caché sets width
to the length of the expression
as a positive integer. A width
value of 0, the null string (""), or a nonnumeric string is treated as a width
of 0, which means that Caché sets width
to the length of the expression
The number of fractional digits. If expression
contains more fractional digits, $JUSTIFY
rounds the fractional portion to this number of fractional digits. If expression
contains fewer fractional digits, $JUSTIFY
pads the fractional portion with zeros to this number of fractional digits, adding a Decimal Separator character, if needed. If decimal
to an integer value and deletes the Decimal Separator character.
If the expression
value is less than 1, $JUSTIFY
inserts a leading zero before the DecimalSeparator character.
$JUSTIFY and $FNUMBER
You can use $FNUMBER
to format a number for display. Both $JUSTIFY
can round (or zero pad) to a specified number of fractional digits. $FNUMBER
can also be used to add NumericGroupSeparator characters. However, note the following:
cannot format a number once it has been right-aligned using $JUSTIFY
interprets the leading spaces as nonnumeric characters.)
cannot perform numeric justification on a number once you have added NumericGroupSeparator characters or have prepended a currency symbol. ($JUSTIFY
interprets NumericGroupSeparators or currency symbols as nonnumeric characters.)
Therefore, to properly add NumericGroupSeparators, round fractional digits, prepend a currency symbol, and right-align the resulting number, you use $FNUMBER
to perform rounding and inserting of NumericGroupSeparators. You then use $JUSTIFY
with 2-parameter syntax to right-align the resulting string:
The following example performs right-justification on strings. No numeric conversion is performed:
WRITE ">",$JUSTIFY("string longer than width",10),"<",!
The following example performs numeric right-justification with a specified number of fractional digits:
SET var1 = 250.50999
SET var2 = 875
return the following lines:
The following example performs numeric right-justification with the $DOUBLE
values INF and NAN:
WRITE !,"Double: ",x
WRITE !,"Double INF minus INF: ",y
© 1997-2019 InterSystems Corporation, Cambridge, MA