Math problem with string result


Closed Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Sep 2005
    Location
    Switzerland
    Posts
    46

    Default Math problem with string result

    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

  2. #2
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    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?
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    and why using STR when you can use DEC?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Sep 2005
    Location
    Switzerland
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    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

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

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

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

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    Join Date
    Sep 2005
    Location
    Switzerland
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    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

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    you'll never get any float as PBP works with integer.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  8. #8
    Join Date
    Sep 2005
    Location
    Switzerland
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    Thanks,
    I'll try like you said.
    I'll come back to you in case of any other trouble.

    Bye
    Lotondo

  9. #9
    Join Date
    Sep 2005
    Location
    Switzerland
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    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

  10. #10
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    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>
    DT

  11. #11
    Join Date
    Sep 2005
    Location
    Switzerland
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    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

Similar Threads

  1. Line Graph, math problem...
    By TerdRatchett in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 6th May 2009, 04:20
  2. Math help please!!!
    By jbirnsch in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 10th August 2007, 14:45
  3. Visual Basic 6 & Access 2000
    By Demon in forum Off Topic
    Replies: 33
    Last Post: - 7th September 2006, 04:39
  4. PicBasic Pro Math Problem??
    By Glen65 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th March 2006, 04:36
  5. PBP 16-bit ADC result math
    By sonic in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 13th March 2005, 14:21

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

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