Sub AppStart (Args() As String)
Log(FormatWithCustomGrouping(123456, 2))
End Sub
'only tested with positive numbers
Private Sub FormatWithCustomGrouping(n As Double, DecimalPoints As Int) As String
Dim Groupings() As Int = Array As Int(3, 2, 1000)
Dim res As StringBuilder
res.Initialize
Dim i As Int = n
Dim s As String = i
Dim f As Double = (n - i) * Power(10, DecimalPoints)
res.Insert(0, NumberFormat2(f, DecimalPoints, 0, 0, False))
res.Insert(0, ".")
Dim index As Int = s.Length - 1
For Each g As Int In Groupings
Do While g > 0
If index < 0 Then Exit
res.Insert(0, s.CharAt(index))
g = g - 1
index = index - 1
Loop
If index >= 0 Then res.Insert(0, ",")
Next
Return res.ToString
End Sub