Me.lblAmt.Caption = FormatIndian(rsCurrent.Fields("suitAmount").Value)Code:Option Explicit Public Function FormatIndian(ByVal Amount As Currency) As String Dim strAmount As String Dim strGrpsArr() As String Dim lngPos As Long Dim lngIndex As Long strAmount = Format$(Amount, "#") 'note: rounding occurs If Len(strAmount) < 4 Then FormatIndian = strAmount Else lngIndex = (Len(strAmount) - 2) \ 2 ReDim strGrpsArr(lngIndex) strGrpsArr(lngIndex) = Mid$(strAmount, Len(strAmount) - 2) 'least significant trio lngPos = Len(strAmount) - 4: lngIndex = lngIndex - 1 'init position variables Do strGrpsArr(lngIndex) = Mid$(strAmount, lngPos, 2) lngPos = lngPos - 2: lngIndex = lngIndex - 1 'update variables If lngPos = 0 Then strGrpsArr(0) = Left$(strAmount, 1) 'leading non-pair group Loop Until lngPos <= 0 FormatIndian = Join(strGrpsArr, ",") Erase strGrpsArr End If End Function Private Sub Form_Load() Dim curTest As Currency curTest = 4456456456716# Debug.Print FormatIndian(curTest) End Sub




Reply With Quote