Solved

Persist Heirarchical Recordset to XML - numeric data precision error

Posted on 2003-12-02
5
237 Views
Last Modified: 2012-05-04
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
Comment
Question by:lutzmj
5 Comments
 
LVL 18

Accepted Solution

by:
bonjour-aut earned 350 total points
Comment Utility
try to enforce with the \ operator

4.9 >> 4.9*10\10

Regards, Franz
0
 
LVL 7

Expert Comment

by:wsteegmans
Comment Utility
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
 
LVL 9

Expert Comment

by:ornicar
Comment Utility
----------------------------------------------------------------------------------------
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now