This post is to discus about Currency formats.
I have Searched on google for showing the price in indian currency like thousand, laks, crores(ex : 1,25,485.86) but there is no simple way to achieve that. Some one write a function to display in laks or crores, that was the base of my function. I have modified and wrote my own function, it may be usefull to all of you.
In VB.Net
——————————————-
Public Function IndianCurrency(ByVal Amount As Object) As String
If IsDBNull(Amount) Or Amount.ToString() = “” Then
Return “0.00″
End If
Amount = Convert.ToDecimal(Amount)
Dim strTmp As String
Dim strResult As String
Dim intLen As Integer
strTmp = Format(Amount, “#.00″)
strResult = Right(strTmp, 6)
intLen = Len(strTmp) – 6
Do While intLen > 0
strTmp = Left(strTmp, intLen)
strResult = Right(strTmp, 2) & “,” & strResult
intLen = Len(strTmp) – 2
Loop
Return strResult
End Function
In C#.Net
——————————————
public string IndianCurrency(object Amount)
{
if (Convert.ToString(Amount) == “” || Amount == null)
{ return “0.00″; }
Amount = Convert.ToDecimal(Amount);
string strTmp = null;
string strResult = null;
int intLen = 0;
strTmp = string.Format(“{0:f}”, Amount);
if (strTmp.Length > 6)
{
strResult = strTmp.Substring(strTmp.Length – 6);
intLen = strTmp.Length – 6;
while (intLen > 0)
{
strTmp = strTmp.Substring(0, intLen);
if (intLen < 2)
{ strResult = strTmp.Substring(0, intLen) + “,” + strResult; }
else
{ strResult = strTmp.Substring(intLen – 2, 2) + “,” + strResult; }
intLen = strTmp.Length – 2;
}
}
else
{ strResult = strTmp; }
return strResult;
}
You can call this function in databinding also
<%# IndianCurrency(Eval(“SellingPrice”))%>
if you want to assign a value to a control then
lblTotal.Text = IndianCurrency( 58745895.5844521);
Another formats
Response.Write(string.Format(“{0:#,##0.00;0.00}”, 558742255555.85562)); - Ans : 558,742,255,555.86
Response.Write(string.Format(“{0:f}”, 558742255555.85562)); - Ans: 558742255555.86
Response.Write(string.Format(“{0:c}”, 558742255555.85562)); - Ans: £558,742,255,555.86
happy coding.