Reading specific digits from a numeric variable

S

Srdjan Kovacevic

How can I read specific digits (e.g. last five digits, or the middle five or
whatever..) from a numerical variable (A)?

The digits I read from variable A, I need to put in another numeric variable
(B).

Thanks in advance!
srdjan
 
T

Tom Ogilvy

use MID/Left,Right The number will be coerced into a string

lngVal = 1234567890
? mid(lngVal,4,5)
45678
? left(lngVal,5)
12345
? right(lngVal,5)
67890
 
R

RADO

One way is to convert your number to a string first (using
CStr function), then use string functions to get your
digits (i.e., Mid(YourNumber, 3, 5)) and convert them back
to numbers.

Another way is to devide your numbers by corresponding
power of 10 and take integer part. I.e., to extract one
digit in the 3-rd position from number 1735, devide it by
mod 10^3 (x mod 10^3) to get 0.735, then multiply by 10^1
to get 7.35, and take integer (7). As you can see, power
of 3 is the starting position, and power of 1 is the
number of digits to extract. You can right a simple
function now.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top