Option Explicit '------------------------------------------------------------------------------- ' ' CStrF(ByVal Single, ByVal Integer) ' ' Converts a floating point number to a string, given desired number of digits ' to right of decimal place. This is the equivalent of a C-language "printf", ' and as such, does not output anything in scientific notation. ' ' This subroutine returns its output in a string named "CStrF_str", which must ' be defined elsewhere as being a public variable of type string (i.e., default ' variable-length string) or boundedstring_N (where N is the string size bound). ' ' This subroutine is coded with RAM usage minimization in mind; some legibility ' loss as well as code bloat is accepted in the interest of eliminating local ' variables. ' ' Eric Seale & Dave Houston -- 7/2002 '------------------------------------------------------------------------------- Sub CStrF( _ ByVal in_sing As Single, _ ByVal rt_digs As Integer) Select Case rt_digs Case 0 CStrF_str = CStr(CInt(Abs(in_sing) - CSng(FixI(Abs(in_sing))))) Case 1 CStrF_str = CStr(CInt((Abs(in_sing) - CSng(FixI(Abs(in_sing)))) * 10.0)) Case 2 CStrF_str = CStr(CInt((Abs(in_sing) - CSng(FixI(Abs(in_sing)))) * 100.0)) Case 3 CStrF_str = CStr(CInt((Abs(in_sing) - CSng(FixI(Abs(in_sing)))) * 1000.0)) Case 4 CStrF_str = CStr(CInt((Abs(in_sing) - CSng(FixI(Abs(in_sing)))) * 10000.0)) Case Else CStrF_str = CStr(CInt((Abs(in_sing) - CSng(FixI(Abs(in_sing)))) * 100000.0)) rt_digs = 5 End select CStrF_str = Mid(CStrF_str, 1, rt_digs) Do While (Len(CStrF_str) < rt_digs) CStrF_str = "0" & CStrF_str Loop if (in_sing < 0.0) then CStrF_str = "-" & CStr(FixI(Abs(in_sing))) & "." & CStrF_str else CStrF_str = CStr(FixI(Abs(in_sing))) & "." & CStrF_str end if End Sub