AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 convert string to decimal
Posted by akshitha on  3/28/2013 8:56:48 AM Category: C#
Add to my favorites
Email to friend
Hi,
I am intermediate at c#, and i want know how to convert string to decimal....

pls.. reply to qu;;

Post Your Reply Post New Question

 Viewer's Reply
Convert String to Decimal in C#
Answered By Moderator1 on 6/28/2013 9:16:51 PM
Below I have given a method, taking in consider several scenarios.

public void ConvertStringDecimal(string stringVal) {
decimal decimalVal = 0;

try {
decimalVal = System.Convert.ToDecimal(stringVal);
System.Console.WriteLine(
"The string as a decimal is {0}.", decimalVal);
}
catch (System.OverflowException){
System.Console.WriteLine(
"The conversion from string to decimal overflowed.");
}
catch (System.FormatException) {
System.Console.WriteLine(
"The string is not formatted as a decimal.");
}
catch (System.ArgumentNullException) {
System.Console.WriteLine(
"The string is null.");
}

// Decimal to string conversion will not overflow.
stringVal = System.Convert.ToString(decimalVal);
System.Console.WriteLine(
"The decimal as a string is {0}.", stringVal);
}
 
Post Your Reply If you still have problem, post it again under this reply for better response.

 
Sponsored by
Sexy Web Design - Free 71 Page Preview!
The PHP Anthology: 101 Essential Tips, Tricks & Hacks, 2nd Edition - Free 207 Page Preview!
Website Magazine