PDA

View Full Version : Getting a value from a few numbers

arch
02-23-2005, 12:08 PM
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

shmoove
02-23-2005, 01:19 PM
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

arch
02-23-2005, 09:30 PM
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

shmoove
02-24-2005, 08:51 AM
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 (http://www.codingforums.com/showthread.php?t=52914).

shmoove

arch
02-26-2005, 09:32 AM
thanks shmoove.

great help from you.

arch

oracleguy
02-27-2005, 12:49 AM
The floor() function may be of some use in this instance as well.

arch
02-28-2005, 01:01 PM
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