Geeks With Blogs

News

Microsoft MVP


DZone MVB


Moderator at CodeASP.NET


Quiz Master







free counters
Free counters
Added on January 19,2012


Follow Me @vmsdurano

A bit About Me



Disclaimer
The opinions expressed herein are my own personal opinions and does not represent the opinions of my employers. Nor does it represent the opinion of my dog, because I don’t have one.


Vinz' Blog (ProudMonkey) "Code, Beer and Music ~ my way of being a programmer"

The following are ways on how to format string number values into a money format with decimals.

Option 1: - Using String.Format method

C#

double formatToMoney;
string num = "1500";
if (double.TryParse(num, out formatToMoney))
{
            string newNum = String.Format("{0:c}", formatToMoney);
            Response.Write(newNum);
}

VB.NET

Dim formatToMoney As Double
Dim num As String = "1500"
If Double.TryParse(num, formatToMoney) Then
    Dim newNum As String = String.Format("{0:c}", formatToMoney)
    Response.Write(newNum)
End If

Option 2: using .ToString() method

C#

double formatToMoney;
string num = "1500";
if (double.TryParse(num, out formatToMoney))
{
            string newNum = formatToMoney.ToString("$#,###.00");
            Response.Write(newNum);
}

VB.NET

Dim formatToMoney As Double
Dim num As String = "1500"
If Double.TryParse(num, formatToMoney) Then
    Dim newNum As String = formatToMoney.ToString("$#,###.00")
    Response.Write(newNum)
End If

That's it! Happy Coding!

Technorati Tags:
Posted on Friday, September 12, 2008 2:01 AM ASP.NET , Tips&Tricks | Back to top


Comments on this post: Formatting String number values to money in ASPNET

comments powered by Disqus

Copyright © Vincent Maverick Durano | Powered by: GeeksWithBlogs.net