Punctuate number at thousands

There are times when you need to display a number punctuated at thousands.

There are times when you need to display a number punctuated at thousands. If it's a number field, then one may enable "Punctuate at thousands" feature, but if the field happens to be a text field then there is no such option. This is where this function comes handy. It takes a source, and after processing, it returns punctuated value. While punctuating, this function takes care of decimals and negative signs. I hope this function would...

make a difference to someone ... somewhere.


Function PunctuateAtThousands(sourceNumber As Variant) As Variant
     Dim tempNumber As Variant
     Dim finalNumber As Variant
     Dim prefix As Variant
     Dim suffix As Variant
     Dim pos As Integer
     '*************************************
     
     If Left(sourceNumber,1)="-"Then
          prefix=Left(sourceNumber,1)
          sourceNumber=Right(sourceNumber,Len(sourceNumber)-1)
     End If
     
     pos=Instr(sourceNumber,".")
     If pos>0 Then
          suffix=Right(sourceNumber,Len(sourceNumber)-(pos-1))
          sourceNumber=Left(sourceNumber,pos-1)
     End If
     
     Do While True
          tempNumber=Trim(Right(sourceNumber,3))
          If Len(tempNumber)=3 Then
               If finalNumber="" Then
                    finalNumber=","+tempNumber
               Else
                    finalNumber=","+tempNumber+finalNumber
               End If
               sourceNumber=Left(sourceNumber,Len(sourceNumber)-3)
          Else
               finalNumber=Trim(tempNumber+finalNumber)
               Exit Do
          End If
     Loop
     
     If Left(finalNumber,1)="," Then
          finalNumber=Right(finalNumber,Len(finalNumber)-1)
     End If
     
     finalNumber=prefix+finalNumber+suffix
     
     PunctuateAtThousands=finalNumber
     
End Function
This was first published in January 2002

Dig deeper on Domino Resources - Part 6

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchEnterpriseLinux

SearchDataCenter

SearchExchange

SearchContentManagement

Close