Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: Getting a value from a few numbers

1. ## Getting a value from a few numbers

hi ppl,

i have a problem with my program where i just need to get the 1st number from a series of the values. Eg : 125 - i need to get the value 5 from the value. do C language has the code in getting the value?

arch

• Originally Posted by arch
do C language has the code in getting the value?
Yes it does.

Now you'll probably ask "what are these codes?". But to answer that we need to know more about the problem. How is this "series of the values" stored in the program? Is it an array? A string? A bunch of int variables?

shmoove

• it's a bunch of int variables which is to be display as a char value. So the output of the program code will be something like :

cout << x << "." << y << z ;

which mean if my result is 128/51 = 2.509, i would like to get the number 2
and if the result is 128/5.1 = 25.09 i like to get the number 5
and 250.0, number to get will be 0.
which i dun tink char variable can be displayed numbers with decimal point.

The final result will display as 2.50.

cheers,
arch

• Well you can use arithmethic operations to achieve this:
If you multiply or divide by 10 you can move the digits around, and the % (modulo) operator gives you the remainder from an integer division so x % 10 will give you the right digit from x.
But if this is all in order to display results on screen then I think you should check this recent thread.

shmoove

• thanks shmoove.

great help from you.

arch

• The floor() function may be of some use in this instance as well.

• hi sorry for the trouble again.

i manage to come out with the display using the %10.
But would like to check if the " % " can be use to transfer the value from the C programming to the PIC chip?

thanks
Arch

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•