![]() |
Reading specific digits from a numeric variable
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 |
Reading specific digits from a numeric variable
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 -- Regards, Tom Ogilvy "Srdjan Kovacevic" wrote in message ... 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 |
Reading specific digits from a numeric variable
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. -----Original Message----- 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 . |
All times are GMT +1. The time now is 03:42 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com