How do I add a decimal point?


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2009
    Location
    Wagoner, USA
    Posts
    52

    Default How do I add a decimal point?

    How do I break down a number to add a decimal point when I send it out to debug or a serial port?
    Example: I have a number like 126 and I want to send out 12.6
    Thanks.

  2. #2
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    HSEROUT [#(number/10),".",#(number//10)]
    Charles Linquist

  3. #3
    Join Date
    Nov 2009
    Location
    Wagoner, USA
    Posts
    52


    Did you find this post helpful? Yes | No

    Default

    That worked great..Thank you.
    And for debug I used:
    Code:
    DEBUG 1," Channel 0: ",DEC(ad0/10),".",DEC(ad0//10),10,13

  4. #4


    Did you find this post helpful? Yes | No

    Default

    You can have a problem with leading zeros in the part after the decimal point, not sure if it effects PBP but it certainly effects picaxe basic.

    Example

    I want to display 102 as decimal with the . between 1 and 0

    1.02

    If you use the method suggested I expect the display will actually show

    1.2 and not 1.02

    It probably works correctly as long there is a number other than 0 present.

    i.e.

    122 would work and display 1.22

    102 would not and would display 1.2 not 1.02.

    Anyone care to comment.

    Here is some picaxe code I use which can probably be adapted for this issue in PBP

    Code:
    VarC = Soc / 100			;Get first part of value (Before decimal point)
    VarA = Soc // 100			;Get second part of value (After decimal point)	
    
    serout Video,BaudT9600,(27,83,0,5,"Soc ",#VarC,".")	;Video Display 
    	
    if VarA < 10 then			;If Leading zero reqd in display due to Value <10 then
    serout Video,BaudT9600,("0",#VarA," % ")	;Video Display
    else
    serout Video,BaudT9600,(#VarA," % ")	;Video Display
    endif
    Last edited by retepsnikrep; - 14th December 2009 at 07:31.

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    122 would work and display 1.22

    102 would not and would display 1.2 not 1.02.

    Anyone care to comment.
    YUP, I will comment..

    The sample code Charles gave will return 10.2 if 102 is entered.
    This will take the last two numbers, even if the numbers are both zero and put them behind the decimal point.
    Code:
    HSEROUT [DEC X/100,".",DEC2 X//100]
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. MAX7219 Helping Hand Please
    By isaac in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 14th February 2014, 15:07
  2. Adding Decimal Point
    By markscotford in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 24th August 2009, 16:12
  3. Decimal point with serout?
    By Kman in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 7th July 2007, 14:33
  4. hex ascii help please
    By ffr58kk90 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 29th December 2006, 21:09
  5. 16bit variable and degrees conversion
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 2nd May 2005, 17:27

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