[bascom] problem with single variable

Discussion in 'Embedded Systems and Microcontrollers' started by king40, May 23, 2014.

  1. king40

    Thread Starter Member

    Jul 17, 2013
    75
    0
    hi engineers :cool:
    i have a single variable
    like this

    dim a as single
    a=12345.12345

    and i config single with this code:
    Config Single = Scientific , Digits = 5

    when i want use of my " a " variable
    my output is
    12345.12
    i dont know why :confused:
    anybody know why ? :(
    thanks
     
  2. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    It's because you are losing resolution with using a Single. Use a Double if you want to capture more data.

    The Single devotes less bits to the fractional portion of the floating point number, than a Double would. Your number is at the limit of what a Single can represent.
     
    king40 likes this.
  3. king40

    Thread Starter Member

    Jul 17, 2013
    75
    0
    with double still have error
     
  4. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    How are you verifying the value?
     
  5. king40

    Thread Starter Member

    Jul 17, 2013
    75
    0
    Dim a as double
    A= 12345.12345
    Dim y as string*20
    Y= str (a)
    LCD y
    Output:
    E3u if i Dnt mistake
     
Loading...