none
Large integer conversion problems RRS feed

  • Question

  • I am using Access 2010 and trying to arithmetically manipulate some large integer values stored as text in a table.  Some of my operations weren't coming out quite right and I noticed the following behavior in the immediate window with one of the values from the table:

    ?format(val("1103334000480529"),"0000000000000000")
    1103334000480530

    ?format(cdbl("1103334000480529"),"0000000000000000")
    1103334000480530

    Val and Cdbl should return doubles, which I thought should easily accomodate a positive 16 digit integer.  Even using val() or cdbl() by themselves in the immediate window don't seem to return the right values:

    ?val("1103334000480529")
     1.10333400048053E+15

    ?cdbl("1103334000480529")
     1.10333400048053E+15 

    Is this some kind of rounding error or will the proper use of format() display the correct value(s)?

    -Bruce

    Tuesday, April 24, 2018 10:52 PM

Answers

  • Hi Bruce Hulsey,

    I try to make a test with Access 2016. Then also I got a same result.

    Then I made a test with "CDec".

    I think it can work for you.

    Reference:

    Type Conversion Functions

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Bruce Hulsey Wednesday, April 25, 2018 9:34 PM
    Wednesday, April 25, 2018 6:34 AM
    Moderator

All replies

  • Hi Bruce,

    Doubles do suffer with some rounding errors. If you don't want or need decimal digits, have you tried CLng() instead?

    Just curious...

    Wednesday, April 25, 2018 2:51 AM
  • CLng would not work in this case - the numbers are greater than 2^32.

    BigInt perhaps? I have not worked with it enough. It's similar to a LongPtr. Of course that's not available in A2010. As theDBGuy said: if using double, roundoff errors are par for the course. Let's not rehash that.


    -Tom. Microsoft Access MVP

    Wednesday, April 25, 2018 3:39 AM
  • Hi Bruce Hulsey,

    I try to make a test with Access 2016. Then also I got a same result.

    Then I made a test with "CDec".

    I think it can work for you.

    Reference:

    Type Conversion Functions

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Bruce Hulsey Wednesday, April 25, 2018 9:34 PM
    Wednesday, April 25, 2018 6:34 AM
    Moderator
  • Until we can make the transition to a later version of Access it looks like CDec() is the way to go.  Thanks!

    -Bruce

    Wednesday, April 25, 2018 9:34 PM