How to

validate and parse decimal

Published: 1. November 2011 | Updated: 1. November 2011
License: Microsoft Public License (MS-PL)
Categories: Converting » Numbers
Tags: C# Conversion Text Validation
Was this snippet helpful for you? YESYES / NONO
string input = "-145.459778";

decimal number;
bool valid = decimal.TryParse(input, out number);

Console.WriteLine("Valid: {0}", valid);
Console.WriteLine("Parsed decimal: {0}", number);
Console Output:
Valid: True
Parsed decimal: -145.459778
Send us feedback about this snippet »



Related Snippets: