Solved

Persist Heirarchical Recordset to XML - numeric data precision error

Posted on 2003-12-02
5
241 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

742 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