ObjectScript Reference
$NUMBER


$NUMBER(num,format,min,max) $NUM(num,format,min,max)
num  The numeric value to be validated and then converted to InterSystems IRIS canonical form. It can be a numeric or string value, a variable name, or any valid ObjectScript expression. 
format  Optional — Specifies which processing options to apply to num. These processing options dictate primarily how to recognize and handle numbers containing decimal points. 
min  Optional — The minimum acceptable numeric value. 
max  Optional — The maximum acceptable numeric value. 
WRITE $NUMBER(07.00,"I")," noncanonical integer numeric",! WRITE $NUMBER(+"07.00","I")," string forced as integer numeric",! WRITE $NUMBER("7","I")," canonical integer string numeric",! WRITE $NUMBER("07.00","I")," noncanonical integer string numeric",! WRITE $NUMBER(07.01,"I")," fractional numeric",! WRITE $NUMBER("07.01","I")," fractional string numeric",!
WRITE !,$NUMBER(4.0,2,0,4) WRITE !,$NUMBER(4.003,2,0,4) WRITE !,$NUMBER(4.006,2,0,4)
SET max=10 WRITE !,$NUMBER(7,,,max) WRITE !,$NUMBER(7,,"",max)
WRITE $NUMBER(mynum,,min,)
WRITE ##class(%SYS.NLS.Format).GetFormatItem("DecimalSeparator")
WRITE ##class(%SYS.NLS.Format).GetFormatItem("NumericGroupSeparator"),! WRITE ##class(%SYS.NLS.Format).GetFormatItem("NumericGroupSize")
SET num="123,456" WRITE !,$NUMBER(num,",") // converts to the fractional number "123.456" // (comma is identified as decimal separator) SET num="123,45,6" WRITE !,$NUMBER(num,",") // returns the null string // (invalid number, too many decimal separators) SET num="123.456" WRITE !,$NUMBER(num,",") // converts to the integer "123456" // removing group separator // (if comma is decimal, then period is group separator) SET num="123.4.56" WRITE !,$NUMBER(num,",") // converts to the integer "123456" // removing group separators // (number and placement of group separators ignored)
SET x=1234.5678 SET y=$DOUBLE(1234.5678) WRITE "Decimal: ",x," rounded ",$NUMBER(x,2),! WRITE "Double: ",y," rounded ",$NUMBER(y,2)