LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Extracting specific digits from a number

Solved!
Go to solution

Hi, 

 

I'm writing something to help my daughter with maths and came across a little problem which I solved, but wondered if there was a neater way of doing it? More out of interest than anything.

 

Essentially I have a two digit number and want to extract what the two digits are to be able to do something with them. So for example if I had the number 59, the first digit would be 5 and the second would be 9.

 

The way I have done it is to convert it to a string and then split the string and then convert it back to a number again.

 

Hardly computationally intensive but just seems inefficient. Is there a better/ neater/ shorter way of doing it?

 

Thanks


Andrew

AndyF_0-1634557980364.png

 

0 Kudos
Message 1 of 4
(2,188 Views)

For a two digit number I would use 'Quotient & Remainder' function and divide by ten.

QaR

Message 2 of 4
(2,177 Views)
Solution
Accepted by AndyF

This is my implementation for a general one, seems to work for digits before decimal and after:

Spoiler
Get Digit.png
Redhawk
Test Engineer at Moog Inc.

Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.

Message 3 of 4
(2,166 Views)

Great, thank you both! Have given Kudos to both, but selected FireFist-Redhawk's as the answer as it provides a greater degree of programmability and also allows my code to be scaleable.

 

Thanks again

 

Andy

 

0 Kudos
Message 4 of 4
(2,095 Views)