Sub NumberSuffix(N As Double) As String
If N < 0 Then
Return "-" & NumberSuffix(-N)
End If
Dim Suffix() As String = Array As String("", "k", "M", "B", "T")
'''Dim Suffix() As String = Array As String("", " Thousand", " Million", " Billion", " Trillion")
Dim Thousands As Int = 0
Do While N >= 1000 And Thousands < Suffix.Length - 1
Thousands = Thousands + 1
N = N / 1000
Loop
If Thousands = 0 Then
'2 decimal places per example of monetary amount including cents
Return NumberFormat2(N, 1, 2, 2, False)
End If
'sufficient decimal places for precision required
Dim MaxDecimalPlaces As Int = 0
Do While MaxDecimalPlaces < 5 'absolute maximum 5 decimal places
Dim RelativeError As Double = Abs(N - Round2(N, MaxDecimalPlaces)) / N
If RelativeError < 0.007 Then 'eg 0.7% (or whatever precision you need)
Exit
End If
MaxDecimalPlaces = MaxDecimalPlaces + 1
Loop
Return NumberFormat2(N, 1, 0, MaxDecimalPlaces, False) & Suffix(Thousands)
End Sub