1. Eszter Zsigmond
  2. PowerBuilder
  3. Wednesday, 29 May 2019

I'm experiencing a problem in connection with string-double conversion in PowerBuilder:

If HKCU/Control Panel/International/LocaleName registry entry is set to a language code with a sub-form of the language (e.g. en-US), and the HKCU/Control Panel/International/sDecimal entry is set to anything, except dot (.), then PB gives a wrong result to string-double conversion (e.g double('1.5') evaluates to 1). If I change the LocaleName entry to a language code without a sub-form (e.g. hu), then the string to double conversion works alright. However, I don't want to modify LocaleName (its current value is en-US). Do you have any idea, where does PB use this registry entry, and how can I fix this problem? (I tried to trace it with Process Monitor, but it gives me no result.)

PB version: Powerbuilder 2017 R3
Database: Oracle Database 12c
OS: Windows 10

Regards,
Eszter

Michael Kramer Accepted Answer Pending Moderation
0
Votes
Undo

Hi Eszter,

Your PB app converts to/from string based on end-user's regional settings at runtime!

AND - while your app runs - user changes regional settings - Bazinga! - Your app may read "123.45" as 123.45 one moment and as 12345 the next moment.

AND - your DB server or DB connection may use different settings. 

So you should avoid depending on string conversion. Less code. Faster performance.

Alternative, write conversion utility that checks at runtime and handles character replacement as part of conversion function.

UPDATE

I wrote a short test app to demo numeric conversion for Byte/Int/Long/LongLong/Decimal/Real/Short and tested various combinations of decimal marker and group marker. I tested for en-US, da-DK, and hu-HU since they use different decimal/grouping markers. These are my results:

Read test results as follows:

Test Result IsNumber(...) returns Converted Number
OK TRUE Correct
FAIL FALSE 0 (value not understood)
WARNING TRUE WRONG! (value misunderstood)

 

Convert FROM string - decimal point - comma grouping - EX: en-US

  1.  OK
    1. Pure digits
    2. Digits + 1 decimal point
    3. Decimal point BEFORE first digit (.789 == 0.789)
    4. Any comma BEFORE decimal point (commas ignored)
  2. WARNING
    1. Comma instead of decimal point (ignored as group marker)
    2. 123,45 == (comma ignored) == 12345
  3. FAIL
    1. Any comma AFTER decimal point (1.23,45 == 0)
    2. Any comma BEFORE/AFTER numeric value (,789 == 0)
    3. Space ANYWHERE in numeric value (123 45 == 0)

Convert FROM string - decimal comma - point grouping - EX: da-DK

  1. OK
    1. Pure digits
    2. Digits + 1 decimal comma
    3. Decimal comma BEFORE first digit (,789 == 0,789)
    4. Any point BEFORE decimal comma (points ignored)
  2. WARNING
    1. Point instead of decimal comma (ignored as group marker)
    2. 123.45 == (point ignored) == 12345
  3. FAIL
    1. Any point AFTER decimal comma (1,23.45 == 0)
    2. Any point BEFORE/AFTER numeric value (.789 == 0)
    3. Space ANYWHERE in numeric value (123 45 == 0)

Convert FROM string - decimal comma - space grouping - EX: hu-HU

  1. OK
    1. Pure digits
    2. Digits + 1 decimal comma
    3. Decimal comma BEFORE first digit (,789 == 0,789)
  2. FAIL
    1. Space ANYWHERE in numeric value (despite space being group marker)
    2. Comma ANWHERE in numeric value (neither decimal nor group marker)

CONCLUSION ::

A:  Mix-up of decimal marker and group marker either ruins the value (IsNumber = false and converted to zero) or results in misunderstood value (IsNumber = TRUE DESPITE converted to wrong value).

B:  PowerBuilder conversion FROM strings can't handle values where SPACE character is group marker.

 

HTH /Michael

Comment
Today migrated to PB 2019 GA #2082. Identical behavior as for PB 2017 R3 #1858.
  1. Michael Kramer
  2. Friday, 31 May 2019
There are no comments made yet.
  1. Thursday, 30 May 2019
  2. PowerBuilder
  3. # 1
Miguel Leeuwe Accepted Answer Pending Moderation
0
Votes
Undo

Also try using Decimal data type variables and the Dec() function instead of Double().

In the past the only windows-settings independent variable was double and also the decimal datatype used to get lots of garbage values after the "." ( such as 0.3999998977999 when assigning a 0.4)

In the latest versions this behaviour seems to have changed and now Double / Real types seem to have problems.

Correct me if I'm wrong

:)

Comment
There are no comments made yet.
  1. Thursday, 30 May 2019
  2. PowerBuilder
  3. # 2
Roland Smith Accepted Answer Pending Moderation
0
Votes
Undo

You should report this as a bug.

Why do you have a numeric value in a string variable in the first place?

Comment
There are no comments made yet.
  1. Thursday, 30 May 2019
  2. PowerBuilder
  3. # 3
Miguel Leeuwe Accepted Answer Pending Moderation
0
Votes
Undo

Hi,

If you're on Oracle, there's a dbparm parameter called "DecimalSeparator" which you can use in your connection string to the database.

I'm not sure if your problem might be fixed if you set this value to what you need: a "," or .... ?

 

regards,

MiguelL

Comment
There are no comments made yet.
  1. Thursday, 30 May 2019
  2. PowerBuilder
  3. # 4
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.