• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 248
  • Last Modified:

Persist Heirarchical Recordset to XML - numeric data precision error

Using Access XP for desktop application. Having trouble persisting data from a hierarchical recordset to XML. Code works and XML document is successfully created, but on closer inspection, some numeric fields that contain decimal data are being converted to higher precision. For example, a value of 3.08 from the Access database is being saved as 3.0799998 in the XML document. All fields exhibiting this problem are set as type Single in the Access database and have a decimal precision from 1 to 6 decimals.

Have tried changing field types in Access to Double with no success.

'##################
'# Code from Application (abbreviated)
'##################
  Dim xmlDoc                As New MSXML2.DOMDocument30
  Dim xmlReceiver           As New MSXML2.DOMDocument30
  Dim xmlHTTP               As New MSXML2.XMLHTTP30
  xmlReceiver.async = False

  With DBConn
   .ConnectionString = _
        "Provider=MSDataShape;Data Provider = Microsoft.Jet.OLEDB.4.0;" & _
    "data source=C:\databasename.mde"
   .Mode = adModeReadWrite
   .Open
  End With

  strSQL = "SHAPE......"

  With RS
    .Open strSQL, DBConn, adOpenDynamic, AdLockOptimistic
    .Save xmlDoc, adPersistXML
    xmlDoc.Save "C:\Temp\Upload.xml"
    Set xmlDoc = Nothing
    .Close
  End With

  Set xmlDoc = New MSXML2.DOMDocument30
  With xmlHTTP
    .Open "POST", g_strWebServer & "/v4_0_upload_data.asp", False, g_strUserName, g_strPassword
    .setRequestHeader "Content-Type", "text/xml"
    xmlDoc.Load "C:\Temp\Upload.xml"
   
    .send xmlDoc.xml


'######################
'#  End Code
'######################

Have not been able to locate any information on this issue. Have been able to reproduce problem on values that have only 1 number after the decimal point (i.e. 4.9) and also on numbers with 2 numbers after the decimal, if the first number is a zero (i.e. 1.02).

In these 2 examples, the XML document would contain 4.899999 and 1.0199999, respectively.

However, this does not occur all the time. Very unpredictable.
0
lutzmj
Asked:
lutzmj
1 Solution
 
bonjour-autCommented:
try to enforce with the \ operator

4.9 >> 4.9*10\10

Regards, Franz
0
 
wsteegmansCommented:
These fields, what is their datatype in your table definition? Single or Double? If so, they indeed generate some unpredictable results, because they behave as a FLOAT datatype.

Instead of using Single/Double, try to use Decimal. This datatype always generates a predictable output. So, change the Field Size in your table definition, or alter your SQL-Statement, using the Format Function ...

Kind Regards!
0
 
ornicarCommented:
----------------------------------------------------------------------------------------
This question has been abandoned and needs to be finalized.
 You can accept an answer, split the points, or get a refund (information at http:/help.jsp#hs5)
  If you need a moderator to help you, post a question at Community Support (http:/Community_Support/)

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

ornicar
Cleanup Volunteer

---------------------------------------------------------------------------------------------
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now