Solved

Persist Heirarchical Recordset to XML - numeric data precision error

Posted on 2003-12-02
5
238 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
ID: 9858147
try to enforce with the \ operator

4.9 >> 4.9*10\10

Regards, Franz
0
 
LVL 7

Expert Comment

by:wsteegmans
ID: 9858657
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
ID: 10075588
----------------------------------------------------------------------------------------
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
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…

815 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

12 Experts available now in Live!

Get 1:1 Help Now