Re: Fomat function?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



If he (the OP) is talking about Significant Digits, then the
standard method is to include as many zeros as needed as place
holders, as they are not significant. Eg;

10000 = 10000
10123 = 10120
123456789 = 123500000

Yes, I think this is what I need actually

http://www.vbforums.com/showthread.php?s=&threadid=269312

(I haven't tried the code, but this is what you need.)

This is not necessarily a particularly good solution to the problem, but the idea behind the question looked interesting enough to give it a try. I am pretty sure the following function will perform a "significant digits" format of an inputted number correctly (including very large and very small numbers that use scientific E-notation)... simply pass it the number to be formatted and the number of significant digits to for that format.

Function FormatSD(ByVal dblInput As Double, SD As Long) As String
Dim P1 As Long
Dim Parts() As String
Parts = Split(Format$(Abs(dblInput), "0.0000000000000000E-0"), "E")
FormatSD = Replace(Format$(CDbl(Parts(0)), "0." & String$(SD - 1, "0")), ".", "")
P1 = Abs(CInt(Parts(1)))
If dblInput <> 0 And (Abs(dblInput) >= 1E+15 Or _
Abs(dblInput) < 0.000000000000009) Then
FormatSD = Format$(Parts(0), "0." & String$(SD - 1, "0")) & "E" & Parts(1)
ElseIf Parts(1) Like "-*" Then
FormatSD = "0." & String$(P1 - 1, "0") & FormatSD
ElseIf Len(FormatSD) <= P1 Then
FormatSD = FormatSD & String$(P1 - Len(FormatSD) + 1, "0")
Else
FormatSD = Format$(FormatSD, String$(P1 + 1, "@") & "." & String$(SD - P1 - 1, "@"))
End If
If Right$(FormatSD, 1) = "." Then FormatSD = Left$(FormatSD, Len(FormatSD) - 1)
If dblInput < 0 Then FormatSD = "-" & FormatSD
End Function


Rick
.



Relevant Pages

  • Re: Formula to consolidate numbers?
    ... everytime the problem happens, are leading zeros involved, right? ... Function returnConnection(strValue As String, Plus As Boolean) As ... Dim a As Double ... at the beginning and end of sub main, ...
    (microsoft.public.excel.misc)
  • Search pattern
    ... Dim strfile As String ... Dim bAddressFound As Boolean ... Dim strCurrentChar As String ...
    (comp.databases.ms-access)
  • Auto Write Name and Merge across
    ... Dim Sheetname01 As String ... Dim WeekName01 As String ...
    (microsoft.public.excel.misc)
  • Re: multiplatform (pocketPC & desktopPC) (Daniel !!)
    ... Friend Versione As String ... Public Sub GetMyConnectionPalmare() ... Dim errorMessages As String ... Private Function GetDS_Desktop(ByVal SQL As String) As DataSet ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: multiplatform (pocketPC & desktopPC) (Daniel !!)
    ... Friend Versione As String ... Public Sub GetMyConnectionPalmare() ... Dim errorMessages As String ... Private Function GetDS_Desktop(ByVal SQL As String) As DataSet ...
    (microsoft.public.dotnet.framework.compactframework)