The IsNumber function returns the incorrect

Symptom

The IsNumber function is returning true for a value that uses a comma as the decimal separator when the regional setting is set to use a period as the decimal separator.  It should return false.

Environment

  • PowerBuilder

  • Windows 7 Server

  • Windows 2008 Server.

Reproducing the Issue

1.  Verify the Windows Control Panel regional settings for the decimal separator is a period:


2.  Test isNumber function with a value using a period "." as the decimal and another number with a comma "," as a decimal.


Code behind the isNumber button:

//The isNumber() returns a boolean.

        //With the regional setting decimal setting as a period. The
        //value tested should return true if the decimal separator is a period
       // and false if the decimal separator is a comma.

        string ls_decimal, ls_comma

        ls_decimal = sle_1.text
ls_comma = sle_2.text

        sle_3.text = string(IsNumber(ls_decimal))
sle_4.text = string(IsNumber(ls_comma))

Cause

This is a product defect that occurs on the Windows 7 and Windows 2008 Server operating systems.

Solution

The following workaround is provided:

long ll_len,ll_flag
int i
string ls_nbr

ll_flag = 0
ls_nbr = "34.39"

// Use IsNumber() to still test for alpha characters
if isnumber(ls_nbr) then

     // move string to char array
     myarray = ls_nbr
     // get the length of the char array or number
     ll_len = upperbound(myarray)
     // find the comma
     for i = 1 to ll_len
          if (myarray[i] = ',') then
          // set a flag indicating comma instead of decimal
            ll_flag = 1
            messagebox("Invalid Number","ls_nbr is not valid--found a comma instead of a decimal")
            return
          end if
     next
else
        messagebox("Invalid Number","ls_nbr is not a
        number-contains alpha characters")
end if