Skip to content

Instantly share code, notes, and snippets.

@tannergooding
Created February 14, 2019 04:06
Show Gist options
  • Save tannergooding/932531266e4e379dd6e14e5c758ed9d3 to your computer and use it in GitHub Desktop.
Save tannergooding/932531266e4e379dd6e14e5c758ed9d3 to your computer and use it in GitHub Desktop.
using System;
using System.Globalization;
public static class DoubleClass
{
public static bool CanBeDouble(string numericStr, out double value)
{
return double.TryParse(numericStr, NumberStyles.Float, CultureInfo.InvariantCulture, out value);
}
}
public class Program
{
static void Main(string[] args)
{
string numStr = "-119.4878";
// string numStr = "-119.48781";
if (DoubleClass.CanBeDouble(numStr, out double value))
{
Console.WriteLine(numStr + " = " +value.ToString("R", CultureInfo.InvariantCulture));
}
else
{
Console.WriteLine("Failed");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment