XML import with XMLDOM, decimal format

Dennis_DecoeneDennis_Decoene Member Posts: 123
Hi,

We have a working xml import with the xml DOM objects. Originally the codeunit was written in a Belgian NAV. Number where read correctly. Now the same codeunit is in a UK Nav DB, running on a pc with locale UK. Numbers are wrong.

This is the XML:
<PROPERTY PROP_NAME="NETAMOUNT1">3173.25</PROPERTY>

In the BE DB this imports as 3.173,25 => Correct
In the UK it imports as 317,325.00 => Wrong

Why?

Comments

  • ara3nara3n Member Posts: 9,256
    the local setting for the computer that identifies 1000 separator is comma and decimal separator is period in one computer and it's different in the other computer.

    check the code how they are assigning the amount. If they are using format, you can write your own code.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • kinekine Member Posts: 12,562
    If you write the value through format, you need to use standard format number 9 to have the output XML compatible (it means use something like this: FORMAT(MyValue,0,9))
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Dennis_DecoeneDennis_Decoene Member Posts: 123
    I looked further into the code that is converting the string to decimal.
    IF NOT EVALUATE(TotalAmount,CONVERTSTR(Value,'.',',')) THEN
      TotalAmount := 0;
    

    Since in BE the decimal sign is "," this works. but for UK, a "," represents the thousand separator, hence wrong...

    So, this would work in UK:
    IF NOT EVALUATE(TotalAmount,Value) THEN
      TotalAmount := 0;
    

    But how to get it right under all circumstances?
  • kinekine Member Posts: 12,562
    If the XML is valid XML, the decimal separator is dot in all cases. Now you can convert the string in this way:
      EVALUATE(MyDecimal,CONVERTSTR(MyDecimalText,'.',DELCHR(FORMAT(0.1),'=','01')))
    

    DELCHR(FORMAT(0.1),'=','01') - result is '.' or ',' depending on local settings
    CONVERTSTR(MyDecimalText,'.',DELCHR(FORMAT(0.1),'=','01')) - replacing '.' (decimal separator in XML) by '.' or ',' depending on local settings
    EVALUATE(..) - you know what it does... ;-)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Dennis_DecoeneDennis_Decoene Member Posts: 123
    damn your smart...
  • kinekine Member Posts: 12,562
    ... I have only catched some things during last 25 years I am working with computers... ;-)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.