PDA

View Full Version : Math problem with string result



Lotondo
- 13th November 2006, 15:05
Hi,
I got lost in something that should be very simple !
Through the cmd serin 2 i get a 4 characters (numbers) Str long\4
example 5894
Then I display it with the cmd LcdOut str long\4
Now it comes the problem.
I should divide /60 the str long\4 (98.2333) and display only 98.
I can not get neither numbers.

Thanks for your help
Lotondo

paul borgmeier
- 13th November 2006, 15:40
L,

Did you rebuild your number before doing the division?

X=5*1000+8*100+9*10+4 ?

If yes, can you post your code snippet?

mister_e
- 13th November 2006, 15:58
and why using STR when you can use DEC?

Lotondo
- 13th November 2006, 16:44
The code here below is working ok but it shows
the number not divided. (ex. 5894)
I tried several ways to divided (ex. /60) this number and
showing the result (Interger or with decimal) but no success.
Bye
Lotondo

>>>>>>>>>>>

DEFINE OSC 4

BAUD VAR BYTE
LATDEC VAR BYTE[4]

RX VAR PORTB.1 ' RX fm 232
BAUD = 188 ' 4800,8,N,1(True,driven)

PORTB=0

LCDOut $FE, 1
LCDOut $FE, $0C

LOOP:

SerIn2 RX,BAUD,[wait("$HOLD,"),SKIP 7,STR LATDEC\4]
Pause 1000

LCDOut $FE, 1
LCDOut "RIS: ",STR LATDEC\4
GoTo LOOP

End

>>>>>>>>>>>>>>>>>>>

mister_e
- 13th November 2006, 17:10
LATDEC var word
SerIn2 RX,BAUD,[wait("$HOLD,"),SKIP 7,DEC4 LATDEC]

Lotondo
- 13th November 2006, 17:39
Mr_e thanks for yr reply.
Now, if I set:

Latfin var byte ------------------> Latfin is Always < 100
Latfin = (Latdec /60)
Lcdout Latfin

Do you think I'll get 98.23 display ?
How to get only 98 ?

Thanks

lotondo

mister_e
- 13th November 2006, 17:51
you'll never get any float as PBP works with integer.

Lotondo
- 13th November 2006, 18:19
Thanks,
I'll try like you said.
I'll come back to you in case of any other trouble.

Bye
Lotondo

Lotondo
- 14th November 2006, 13:01
Here i am again !
I partialy solved my problem but I believe it's possibile in a better way.
As I said i'm getting a string : $HOLD,-xrt4qw5101*A
Mister_e told me to use:
LATDEC var word
SerIn2 RX,BAUD,[wait("$HOLD,"),SKIP 7,DEC4 LATDEC]
This works great but the 5101 has to be divided then by 10000 and multiplied by 60, the result 30 has to be shown with LcdOut.
I was not able to make it works.
Here what I did, it works but .............. :
L1 VAR BYTE
L2 VAR BYTE
L3 VAR BYTE
L4 VAR BYTE
LATDEC VAR WORD
SerIn2 RX,BAUD,[wait("$HOLD,"),SKIP 7,L1,L2,L3,L4]
LATDEC = ((((L1-48)*1000)+((L2-48)*100)+((L3-48)*10)+(L4-48))*6)/1000
LcdOut "Result: ", " ", #LATDEC

Thanks for any further help
Lotondo

Darrel Taylor
- 14th November 2006, 21:44
Which formula do you need?

In the first post, you said you needed the 4 digit number divided by 60.
5894 / 60 = 98.233

Now it seems that multiplying by 0.006 is what you are looking for.
5894 * 6 / 1000 = 35.364
5101 * 6 / 1000 = 30.606

Either way, you can still use mister_e's example instead of all the multiplications.

LATDEC var word
SerIn2 RX,BAUD,[wait("$HOLD,"),SKIP 7,DEC4 LATDEC]

Then depending on which formula you actually need, do one of these...

LATDEC = LATDEC * 6 / 1000
LcdOut "Result: ", " ", #LATDEC

-- OR --

LATDEC = LATDEC / 60
LcdOut "Result: ", " ", #LATDEC

<br>

Lotondo
- 15th November 2006, 10:06
Great !
It's working now.
I made for sure a mistake, cause I did again what Mister_e said
and now it's ok.

Thanks
Lotondo