Function to convert money value to pure indian type

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ravitunk
    New Member
    • Jun 2007
    • 88

    Function to convert money value to pure indian type

    hi all....i have a string which accepts money...in any form like...123456 or 1,23,456.00 or 3456.00...... finally i want it to be coverted to...1,23,456.0 0, 3,456.00 (comma after lakhs,thousands ....with a double digit precision)....p lease tell me if there is any fucntion or a code to accomplish this ASAP....
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    you need to use the FORMAT function for the purpose.

    Comment

    • ravitunk
      New Member
      • Jun 2007
      • 88

      #3
      hey thks for reply...i know format function helps in tht case..but its returning the value as....123,456.0 0..if the input is more than 1lakh......also i used formatnumber... enen then the result is same....i want it to return...as...1 ,23,456.00..... ..reply me ASAP....thks for any kind of help...

      Originally posted by debasisdas
      you need to use the FORMAT function for the purpose.

      Comment

      • debasisdas
        Recognized Expert Expert
        • Dec 2006
        • 8119

        #4
        try like this

        Format(12345678 .00004, "###,###,###.## ###")


        AND DO NOT START A DUPLICATE THREAD FOR THE SAME QUESTION

        Comment

        • QVeen72
          Recognized Expert Top Contributor
          • Oct 2006
          • 1445

          #5
          Hi,

          I Guess, using any Combination of Locale setting and Format, you would end up with a Digit grouping of 3 Digits..
          You can write a Format function of your own..
          Try this :

          [code=vb]
          Private Function MyFormat(ByVal TNum As String) As String
          '
          Dim TStr As String
          Dim OStr As String
          Dim TempStr As String
          '
          TNum = Replace(TNum, ",", "")
          '
          OStr = Format(TNum, "0.00")
          TStr = Right(OStr, 6)
          If Len(OStr) <= 6 Then
          MyFormat = TStr
          Else
          OStr = Left(OStr, Len(OStr) - 6)
          Do
          TempStr = Right(OStr, 2)
          TStr = TempStr & "," & TStr
          OStr = Left(OStr, Len(OStr) - Len(TempStr))
          Loop Until Trim(OStr) = ""
          MyFormat = TStr
          End If
          '
          End Function
          [/code]

          To Call this Function, use this code:
          [code=vb]
          Private Sub Text1_LostFocus ()
          Text1.Text = MyFormat(Text1)
          End Sub
          [/code]

          Regards
          Veena

          Comment

          • ravitunk
            New Member
            • Jun 2007
            • 88

            #6
            thks for the reply..but the result it generates is....12,345,67 8.00004......wi ch is not i wanted....plz it should seperate lakhs with a comma...thousan ds with a comma...and so on.....the output should be like....1,23,45 ,678.00......pl z help me out....

            Originally posted by debasisdas
            try like this

            Format(12345678 .00004, "###,###,###.## ###")


            AND DO NOT START A DUPLICATE THREAD FOR THE SAME QUESTION

            Comment

            • debasisdas
              Recognized Expert Expert
              • Dec 2006
              • 8119

              #7
              cant you change the position of comma ?

              Comment

              • smartchap
                New Member
                • Dec 2007
                • 236

                #8
                Code from QVeen works fine but after modifying for a negative number.

                Comment

                • VijaySofist
                  New Member
                  • Jun 2007
                  • 107

                  #9
                  Hi!

                  Here is the Code you are looking for. Please Find the attachment here with this post.

                  With Regards
                  Vijay. R
                  Attached Files

                  Comment

                  • ravitunk
                    New Member
                    • Jun 2007
                    • 88

                    #10
                    infact..i shud say thks to veena(QVeen72 )....tht code worked well...thks a lot..for ur help..


                    Originally posted by QVeen72
                    Hi,

                    I Guess, using any Combination of Locale setting and Format, you would end up with a Digit grouping of 3 Digits..
                    You can write a Format function of your own..
                    Try this :

                    [code=vb]
                    Private Function MyFormat(ByVal TNum As String) As String
                    '
                    Dim TStr As String
                    Dim OStr As String
                    Dim TempStr As String
                    '
                    TNum = Replace(TNum, ",", "")
                    '
                    OStr = Format(TNum, "0.00")
                    TStr = Right(OStr, 6)
                    If Len(OStr) <= 6 Then
                    MyFormat = TStr
                    Else
                    OStr = Left(OStr, Len(OStr) - 6)
                    Do
                    TempStr = Right(OStr, 2)
                    TStr = TempStr & "," & TStr
                    OStr = Left(OStr, Len(OStr) - Len(TempStr))
                    Loop Until Trim(OStr) = ""
                    MyFormat = TStr
                    End If
                    '
                    End Function
                    [/code]

                    To Call this Function, use this code:
                    [code=vb]
                    Private Sub Text1_LostFocus ()
                    Text1.Text = MyFormat(Text1)
                    End Sub
                    [/code]

                    Regards
                    Veena

                    Comment

                    Working...