Can I hold Integers in a Double?

aidan

Registered User.
Local time
Today, 10:57
Joined
May 23, 2005
Messages
34
I have a "number" field which is 12 characters long, called CID held as a string.

In the first record it has the value 360126474291

Basically, I wanted to do nextCID = val(lastCID) + 167, but obviously (:o) I get an overflow, so I can't.

What can I expect if I use nextCID = CDbl(lastCID) + 167 ?

Will it behave as though I'm adding 64 bit integers?

Aidan
 
When CID is a text field in a table containing the string 360126474291,
on my system val(CID)+167 in a query returns 3.60126474458E+11 (not an overflow error.)


In the same query, trim(str(CID+167)) returns a text string 360126474458
.
 
...if you must go numeric for some reason, use CCur() in place of CDbl() to avoid any risk of unwanted behaviour from the float's imprecision.

currency type gives you 10^3 breathing space with 15 digits before the decimal vs 12 in your example (actually, it gives just a touch less than the full 15 digits) and uses integer math.

izy
 
I put this in the control source of an unbound text box (txtNextCID) on a bound form:-
=Trim(Str([CID]+167))

which returned the string 360126474458. So Jon's expression Trim(Str([CID]+167)) works in VBA, too.


When I increased CID to 15 digits (360126474291999), the expression
=Trim(Str([CID]+167)) still worked (returning the string 360126474292166)


Since what you want is a text string for the next CID, I don't think you need any of the conversion functions CDbl(), CCur() etc.

^
 
Jon and Emp: Thanks - I didn't know you could use a string in an expression like that, but why the need for trim?

Izy: I'll bear that in mind for the future, thanks.
 
Remarks

When numbers are converted to strings, a leading space is always reserved for the sign of number. If number is positive, the returned string contains a leading space and the plus sign is implied.

The above is from Access's help file for the Str() function.

I just trimmed the leading space.
.
 

Users who are viewing this thread

Back
Top Bottom