Skip to main content

European and American Decimal Separators

European and American Decimal Separators

$NUMBER returns a number in canonical form, removing all numeric group separators and includes at most one decimal separator character. You can use the format values “,” or “.” to identify the decimal separator used in num; by specifying the decimal separator, you are also implicitly specifying the numeric group separator.

To determine the DecimalSeparator character for your locale, invoke the following method:

  WRITE ##class(%SYS.NLS.Format).GetFormatItem("DecimalSeparator")

To determine the NumericGroupSeparator character and NumericGroupSize number for your locale, invoke the following methods:

  WRITE ##class(%SYS.NLS.Format).GetFormatItem("NumericGroupSeparator"),!
  WRITE ##class(%SYS.NLS.Format).GetFormatItem("NumericGroupSize")

In following examples, a comma is specified as the decimal separator:

  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)
FeedbackOpens in a new tab