Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Persist Heirarchical Recordset to XML - numeric data precision error

Posted on 2003-12-02
5
Medium Priority
?
246 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 1400 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

609 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