Formatted numeric output: Difference between revisions

Content added Content deleted
mNo edit summary
Line 1,841: Line 1,841:
{{out}}
{{out}}
<pre>00007.125</pre>
<pre>00007.125</pre>

=={{header|VBA}}==
<lang vb>Option Explicit

Sub Main()
Debug.Print fFormat(13, 2, 1230.3333)
Debug.Print fFormat(2, 13, 1230.3333)
Debug.Print fFormat(10, 5, 0.3333)
Debug.Print fFormat(13, 2, 1230)
End Sub

Private Function fFormat(NbInt As Integer, NbDec As Integer, Nb As Double) As String
'NbInt : Lenght of integral part
'NbDec : Lenght of decimal part
'Nb : decimal on integer number
Dim u As String, v As String, i As Integer
u = CStr(Nb)
i = InStr(u, Application.DecimalSeparator)
If i > 0 Then
v = Mid(u, i + 1)
u = Left(u, i - 1)
fFormat = Right(String(NbInt, "0") & u, NbInt) & Application.DecimalSeparator & Left(v & String(NbDec, "0"), NbDec)
Else
fFormat = Right(String(NbInt, "0") & u, NbInt) & Application.DecimalSeparator & String(NbDec, "0")
End If
End Function
</lang>
{{out}}
<pre>0000000001230.33
30.3333000000000
0000000000.33330
0000000001230.00</pre>


=={{header|VBScript}}==
=={{header|VBScript}}==