For p = -3 TO 3 Print uFormat$(6258.990876,p) Next p
60006300626062596259.06258.996258.991
' The function Function uFormat$(x,p) ' given a number (x) and the required number of decimal places (p) ' returns formatted string. Negative and zero p is permitted Local f$ f$=Str$(Cint(x*10^p)) If Len(f$)<=p Then f$=String$(p+1-Len(f$), "0")+f$ EndIf If p>0 Then uFormat$=Left$(f$,Len(f$)-p)+"."+Right$(f$,p) ElseIf p = 0 Then uFormat$=f$ Else uFormat$=f$+String$(Abs(p),"0") EndIf End Function
q=.000001 Print StrE$(q,1,1),,StrE$(q,5,0) q=.0001 Print StrE$(q,2,1),,StrE$(q,5,0) q=.01 Print StrE$(q,3,1),,StrE$(q,5,0) q=.455 Print StrE$(q,4,1),,StrE$(q,5,0) q=0 Print StrE$(q,4,1),,StrE$(q,5,0) q=1 Print StrE$(q,5,1),,StrE$(q,5,0) q=7748 Print StrE$(q,6,1),,StrE$(q,5,-1) q=100000 Print StrE$(q,7,1),,StrE$(q,5,-1) q=2200000 Print StrE$(q,8,1),,StrE$(q,5,0)
1.0e-6 1.00000e-6 100.00e-6 1.00000e-4 10.000e-3 1.00000e-2 455.0000e-3 4.55000e-1 0.0000 0.00000 1.00000e0 1.00000e0 7.748000e3 7.74800e3 99.9999923e3 100.00000e3 2.20000004e6 2.20000e6
' the function Function strE$(mx,p,eng) ' mx = number to format ' p = number of decimal places ' if eng is not zero, use engineering notation Local sn$ Local Float x,px sn$=" " x=mx If x<0 Then sn$="-" x=x*-1 EndIf If x<>0 Then ' zero is a special case px=Int(Log(x)/Log(10)) If eng<>0 Then ' engineering notation - multiples of 3 px=Int(px/3)*3 EndIf x=x*(10^-px) strE$=sn$+Str$(x,0,p)+"e" ' if Sgn(Int(px))<>-1 Then strE$=strE$+"+" ' un-REM this line to force the exponent sign e.g. 1e+6 instead of 1e6 strE$=stre$+Str$(Int(px)) Else strE$=sn$+Str$(x,0,P) EndIf End Function