Re: Fomat function?
- From: "Rick Rothstein \(MVP - VB\)" <rickNOSPAMnews@xxxxxxxxxxxxxxxxx>
- Date: Tue, 3 Apr 2007 15:43:12 -0400
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
.
- References:
- Re: Fomat function?
- From: Michael Cole
- Re: Fomat function?
- Prev by Date: Re: bahhhh thanks all!!
- Next by Date: Re: VS6EE and goodies
- Previous by thread: Re: Fomat function?
- Next by thread: VB 6 and Vista problem
- Index(es):
Relevant Pages
|