TGC Codebase Backup



Enhanced Number to String by draicker2003

24th Jun 2004 9:30
Summary

This Function Can change real numbers into string that can be writen in a file as a string Better than code "182" = Str$(182)



Description

This Function Can change real numbers into string that can be writen in a file as a string
in the version provided by darkbasic this could only convert hole numbers into a String that could be written in a file



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    Function RealStr$(Msg#)
   In = Int(Msg#)
   If In = Msg#
      St$ = Str$(In)
   Else
      Ab = Abs(In)
      Tmp2$ = Str$(In)
      Kom = Len(Tmp2$)
      If In = 0
         Tmp2$ = "0"
      Else
         Tmp2$ = ""
      EndIf
      If Ab = In
         Str1$ = ""
      Else
         Str1$ = "-"
      EndIf
      Be2# = Msg#
      For X = 1 to 200
          Be1# = Be2# * 10
          Be2# = Be1#
          If Int(Be2#) = 0
             Tmp1$ = Tmp2$ + "0"
             Tmp2$ = Tmp1$
          EndIf
      Next X
      T$ = Str$(Abs(Int(Be2#)))
      Tmp3$ = Str1$ + Tmp2$ + T$
      Tmp2$ = Tmp3$
      Ty = Len(Tmp2$)
      R$ = Right$(Tmp2$,1)
      While R$ = "0"
         Ty2 = Ty - 1
         Ty = Ty2
         Tmp1$ = Left$(Tmp2$,Ty)
         Tmp2$ = Tmp1$
         R$ = Right$(Tmp2$,1)
      EndWhile
      Ki = Ty2
      Tmp3$ = Tmp2$
      Si = Ki - Kom
      Str1$ = Left$(Tmp3$,Kom)
      Str2$ = Right$(Tmp3$,Si)
      St$ = Str1$ + "." + Str2$
   EndIf
EndFunction St$

Function SpefRealStr$(Msg#,Conter)
   In = Int(Msg#)
   If In = Msg#
      St$ = Str$(In)
   Else
      Ab = Abs(In)
      Tmp2$ = Str$(In)
      Kom = Len(Tmp2$)
      If In = 0
         Tmp2$ = "0"
      Else
         Tmp2$ = ""
      EndIf
      If Ab = In
         Str1$ = ""
      Else
         Str1$ = "-"
      EndIf
      Be2# = Msg#
      For X = 1 to Conter
          Be1# = Be2# * 10
          Be2# = Be1#
          If Int(Be2#) = 0
             Tmp1$ = Tmp2$ + "0"
             Tmp2$ = Tmp1$
          EndIf
      Next X
      T$ = Str$(Abs(Int(Be2#)))
      Tmp3$ = Str1$ + Tmp2$ + T$
      Tmp2$ = Tmp3$
      Ty = Len(Tmp2$)
      R$ = Right$(Tmp2$,1)
      While R$ = "0"
         Ty2 = Ty - 1
         Ty = Ty2
         Tmp1$ = Left$(Tmp2$,Ty)
         Tmp2$ = Tmp1$
         R$ = Right$(Tmp2$,1)
      EndWhile
      Ki = Ty2
      Tmp3$ = Tmp2$
      Si = Ki - Kom
      Str1$ = Left$(Tmp3$,Kom)
      Str2$ = Right$(Tmp3$,Si)
      St$ = Str1$ + "." + Str2$
   EndIf
EndFunction St$