Announcement

Collapse
No announcement yet.

format$

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Lance Edmonds
    replied
    I'll ask R&D on your behalf...



    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Charles Dietz
    replied
    Lance, perhaps PowerBasic could truncate the decimal places to 18 as I do
    in the code below using MyFormat()

    Code:
    #COMPILE EXE
    #DIM ALL
    DECLARE FUNCTION MyFormat(x AS EXT, s AS STRING) AS STRING
    
    FUNCTION PBMAIN() AS LONG
       DIM x AS EXT   ' single: similar results
       ON ERROR GOTO Er
       x=1/3
       MSGBOX STR$(x)                                    ' = .333333333333333
       MSGBOX MyFormat(x,"##.######################")    ' = 0.033333333333333331200
       MSGBOX STR$(x)                                    ' No error now
       EXIT FUNCTION
    Er:: MSGBOX "ERROR"
    END FUNCTION
    
    FUNCTION MyFormat(x AS EXT, s AS STRING) AS STRING
       LOCAL n AS LONG
       n = INSTR(s, ".")
       IF LEN(s) - n > 18 THEN
          s = LEFT$(s, n) + MID$(s, n+1, 18)
       END IF
       FUNCTION = FORMAT$(x, s)
    END FUNCTION
    ------------------

    Leave a comment:


  • Hanns Ackermann
    replied
    Thanks Lance,

    I didn't found this limitation in my helpfile. But I'm still
    wondering about the results of the last two str$(x) ....

    Regards, Hanns.


    ------------------

    Leave a comment:


  • Lance Edmonds
    replied
    Format$() is limited to 18 decimal places... after that you get undefined results which can affect the appearance of the returned strings.

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Hanns Ackermann
    started a topic format$

    format$

    Just had a little problem with format$ but wasn't able to fix it.
    However, playing around with format$ I repeatedly got strange
    results similar to my original one, i.e. different results of x=1/3
    depending on the mask$ given in format$(x,mask$). In the following
    code I listed the results of msgbox/format$ at the end of the
    respective line. The behaviour of the program is similar after
    substituting ext by single. I feel that the problem was already
    discussed somewhere in this forum, but couldn't find anything.
    Am I doing anything wrong? I'm using PII/NT4/PB6. Any idea?

    Regards, Hanns.


    Code:
    #compile exe
    
    function pbmain() as long
    
         dim x as ext   ' single: similar results
       
         On Error Goto Er
       
         x=1/3
         msgbox str$(x)                                    ' = .333333333333333
         msgbox format$(x,"##.####################")       ' =0.033333333333333331200
         msgbox format$(x,"##.##################")         ' =0.333333333333333312
         msgbox format$(x," ##.#####################")     ' =0.00333333333333333312000
         msgbox format$(x,"#.#######################^^^^") ' = .333333333333333
         msgbox str$(x)                                    ' =0 !!!!!!!!!!!!!!
         x=x+0.5
         msgbox str$(x)                                    ' =0 !!!!!!!!!!!!!!
         
         exit function
         
    Er:: msgbox "ERROR"
    
    end function

    ------------------


    [This message has been edited by Hanns Ackermann (edited August 23, 2000).]
Working...
X