Page 1 of 1

How to extract number

Posted: August 14th, 2012, 3:36 am
by khurshid.arshad
Dear Gregory


"123456789" I want to extract single digit or double digit from any position.


Regards.

Re: How to extract number

Posted: August 14th, 2012, 3:53 am
by Gregory Martin
If this is a numeric value, you may find it most easy to convert it to a string first. For example, to get the first two digits, you could write:
maketext("%d",xxx)[1:2]
However, that will return it as a string. If you want it as a number again, you can write this:
tonumber(maketext("%d",xxx)[1:2])
If you want digits from the right of the string, you could use the modulo operator. The last two digits are:
xxx % 100
You can use divide and modulo to get middle sections of the string. For example, to get the tens and hundred digits, you would write:
( xxx / 10 ) % 100

Re: How to extract number

Posted: August 14th, 2012, 2:48 pm
by khurshid.arshad
Dear Gregory

Thanks.

arshad