Menu

how convert a float point variable to string

Manuel
2022-02-03
2022-02-03
  • Manuel

    Manuel - 2022-02-03

    Yo he buscado en la ayuda de GCB si hay alguna instrucción para convertir una variable en punto flotante a
    una cadena pero no la he encontrado.
    he intentado

    cadena = str32(1234.5678)
    y cuando imprimo cadena el resultado es "RÜD1234"
    existe otra manera ?

     
  • stan cartwright

    stan cartwright - 2022-02-03

    If I wanted floats then strings would be a solution. I'm just mulling how to do it.
    I'd need to get the value before the decimal point then the value after. It would be either difficult or easy depending on ones knowledge of maths.
    I can live without floats. They would make converting arduino code easier as using pi is common.

     
    • Anobium

      Anobium - 2022-02-03

      dim display_string as String * 4
      dim valor_calc as Long
      valor_calc = 99989991 'treat xxxx.yyyy

      do

      HSerPrint " comienzo2"
      HSerPrintCRLF
      HSerPrint "numero "
      
      display_string = str( valor_calc / 10000 )
      display_string = LeftPad ( display_string, 4, "0" )
      HSerPrint display_string
      
      HSerSend "."
      
      display_string = str(valor_calc % 10000 )
      display_string = LeftPad ( display_string, 4, "0" )
      HSerPrint display_string
      
      HSerPrintCRLF
      HSerPrint " finalizado"
      HSerPrintCRLF
      wait 1 s
      
      valor_calc++
      

      loop

       
  • William Roth

    William Roth - 2022-02-03

    I think the use of the term "reals" to exclusively mean decimal or floating point numbers is confusing. Integers are also "real" numbers as are fractions.

    It may be less confusing to say that:

    "Great Cow Basic does not support floating point mathematics at this time".

    Bill

     
  • stan cartwright

    stan cartwright - 2022-02-03

    Lots of commands I'm unfamiliar with.
    I'm not good at maths, mantissa, exponent yawn.
    I do sums in my head but not the way I learnt in school... no pen & paper.
    I've seen youtube vids about quick +-*/

     
  • stan cartwright

    stan cartwright - 2022-02-03

    The zxpectrum used floats as default even if you used whole numbers, probably why it was slow basic.
    Why not rip off arduino floats?
    I posted a pseudo decimal point and I used string functions. 5V meter

      adcval=adcval*100
      adcval=adcval/51
      volts=str(adcval)
      if adcval<10 then
        volts="0.0"+left(volts,1,1)
        goto volt_format_done
      end if
      if adcval<100 then
        volts="0."+mid(volts,1,2)
      else
        volts=left(volts,1,1)+"."+mid(volts,2,2)
      end if
    
     
    • Anobium

      Anobium - 2022-02-03

      Great stuff.

       
  • stan cartwright

    stan cartwright - 2022-02-03

    I think using strings to represent floats would be the way but needs some thought to implement and maths know how. It all ends up with rotating stuff and strings can be rotated easy but that idea won't work.
    Floats are an interesting idea but can we live without it?

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.