Click here to Skip to main content
15,891,409 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more: , +
hi....

The code is about place the comma's (,) i.e separator between numbers
in this format (12,21,21,123) it works good..

but when there's a decimal point such as 12345.58 it will show as 12,346..
it will round up the values.. ( which i dont want that .. i want as it value to be printed )

and one more problem if there five digit with two decimal i.e(12345.00) it will show correct
i.e (12,345.00) but if i there four digit with two decimal i.e(1234.00 ) it will show this #error

[code]

VB
Public Function FormatIndian(ByVal Amount As decimal) As String  
Dim strAmount As String
Dim strGrpsArr() As String
Dim lngPos As Long
Dim lngIndex As Long

   strAmount = Format$(Amount, "#")
   If Len(strAmount) < 4 Then
      FormatIndian = strAmount
   Else
      lngIndex = (Len(strAmount) - 2) \ 2
      ReDim strGrpsArr(lngIndex)
     
      strGrpsArr(lngIndex) = Mid$(strAmount, Len(strAmount) - 2)
     
      lngPos = Len(strAmount) - 4:  lngIndex = lngIndex - 1
      Do
         strGrpsArr(lngIndex) = Mid$(strAmount, lngPos, 2)
         lngPos = lngPos - 2:       lngIndex = lngIndex - 1
         If lngPos = 0 Then strGrpsArr(0) = Left$(strAmount, 1)
      Loop Until lngPos <= 0
     
      FormatIndian = Join(strGrpsArr, ",")
      Erase strGrpsArr
   End If
        Return  FormatIndian 
End Function

[/code]

please modify the code .. the code is in ssrs report properties->code tab..
help me...
Posted
Updated 3-Nov-10 21:32pm
v2

Hi,

This method could be helpful for you in acheiving your task:

C#
static string FormatToIndianNotation(decimal amount)
        {
            string strAmount = amount.ToString();
            string amountInIndianNotation = "";
            string fraction = "";
            if (strAmount.Contains("."))
            {
                fraction = strAmount.Split('.')[1];
                strAmount = strAmount.Split('.')[0];
            }
            if (strAmount.Length >= 3)
            {
                amountInIndianNotation = strAmount.Substring(strAmount.Length - 3);
                strAmount = strAmount.Remove(strAmount.Length - 3);
            }
            while(strAmount.Length!=0)
            {
                if (strAmount.Length <= 2)
                {
                    if (amountInIndianNotation.Length != 0)
                        amountInIndianNotation = strAmount + "," + amountInIndianNotation;
                    else
                        amountInIndianNotation = strAmount;
                    strAmount = "";
                }
                else
                {
                    amountInIndianNotation = strAmount.Substring(strAmount.Length - 2) + "," + amountInIndianNotation;
                    strAmount = strAmount.Remove(strAmount.Length - 2);
                }
            }
            return amountInIndianNotation + "." + fraction;
        }



Thanks,
DotNetGeek
 
Share this answer
 
Comments
Maggi3 8-Nov-10 11:54am    
Can you post the VB code for this?
anandkumarrs6 24-Mar-11 9:06am    
This code works perfectly...thanks
Hi
I think we can use globalization features

VB
' For globalization
Imports System.Globalization

' For Indian currency format
Dim ci As New CultureInfo( "en-in" )
Dim someRealValue As Double = 1234.567
Dim currencyFormat As String
currencyFormat = someRealValue.ToString( "C", ci );
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900