11.07.2015 Views

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - InterSystems Documentation

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

The scale parameter value causes the returned value to be a rounded or truncated version ofthe num value. The actual value of the num variable is not changed by $NORMALIZE processing.scaleThe mandatory scale parameter is used to specify how many decimal digits to round to.Depending on the value specified, scale can have no effect on decimal digits, round to aspecified number of decimal digits, round to an integer, or truncate to an integer.A non-negative scale value causes num to be rounded to that number of decimal digits. Whenrounding, a value of 5 or greater is always rounded up. To avoid rounding of a decimalnumber, make scale larger than the number of possible decimal digits in num. A scale valueof 0 causes num to be rounded to an integer value (3.9 = 4). A scale value of –1 causes numto be truncated to an integer value (3.9 = 3). A scale value which is non-numeric or the nullstring is equivalent to a scale value of 0.Specify an integer value for scale; decimal digits in the scale value are ignored. You canspecify a scale value larger than the number of decimal digits specified in num. You canspecify a scale value of –1; all other negative scale values result in a error.ExamplesIn the following example, each invocation of $NORMALIZE returns the normalized versionof num with the specified rounding (or integer truncation):WRITE !,$NORMALIZE(0,0) ; All integers OKWRITE !,$NORMALIZE("",0) ; Null string is parsed as 0WRITE !,$NORMALIZE(4.567,2) ; Decimal numbers OKWRITE !,$NORMALIZE("4.567",2) ; Numeric strings OKWRITE !,$NORMALIZE(-+.0,99) ; Leading/trailing signs OKWRITE !,$NORMALIZE(+004.500,1) ; Leading/trailing 0's OKWRITE !,$NORMALIZE(4E2,-1) ; Exponents OKIn the following example, each invocation of $NORMALIZE returns a numeric subset ofnum:WRITE !,$NORMALIZE("4,567",0); NumericGroupSeparators (commas) are not recognized; here validation halts at the comma, and 4 is returned.WRITE !,$NORMALIZE("4A",0); Invalid (non-numeric) character halts validation; here 4 is returned.$NORMALIZEThe following example shows the use of the scale parameter to round (or truncate) the returnvalue:<strong>Caché</strong> <strong>ObjectScript</strong> <strong>Reference</strong> 269

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!