AcTools.Utils.Helpers.FlexibleParser.TryParseDouble C# (CSharp) Method

TryParseDouble() public static method

public static TryParseDouble ( [ s, double &value ) : bool
s [
value double
return bool
        public static bool TryParseDouble([CanBeNull] string s, out double value) {
            if (s == null) {
                value = 0d;
                return false;
            }

            if (double.TryParse(s, NumberStyles.Any, CultureInfo.InvariantCulture, out value)) {
                return true;
            }

            if (_parseDouble == null) {
                _parseDouble = new Regex(@"-? *\d+([\.,]\d*)?", RegexOptions.Compiled);
            }

            var match = _parseDouble.Match(s);
            if (match.Success) {
                return double.TryParse(match.Value.Replace(',', '.').Replace(" ", ""), NumberStyles.Any,
                                       CultureInfo.InvariantCulture, out value);
            }

            value = 0.0;
            return false;
        }

Same methods

FlexibleParser::TryParseDouble ( string s ) : double?

Usage Example

Beispiel #1
0
        public GeoTagsEntry(string lat, string lng)
        {
            Latitude  = lat;
            Longitude = lng;

            LatitudeValue  = FlexibleParser.TryParseDouble(Latitude);
            LongitudeValue = FlexibleParser.TryParseDouble(Longitude);

            if (LatitudeValue.HasValue && Math.Abs(LatitudeValue.Value) > 90d)
            {
                LatitudeValue = null;
            }

            if (LongitudeValue.HasValue && Math.Abs(LongitudeValue.Value) > 180d)
            {
                LongitudeValue = null;
            }

            IsEmptyOrInvalid = !LatitudeValue.HasValue || !LongitudeValue.HasValue;
            if (IsEmptyOrInvalid)
            {
                return;
            }

            if (Latitude.ToLower().Contains("s"))
            {
                LatitudeValue = -Math.Abs(LatitudeValue ?? 0d);
            }

            if (Longitude.ToLower().Contains("w"))
            {
                LongitudeValue = -Math.Abs(LongitudeValue ?? 0d);
            }
        }
All Usage Examples Of AcTools.Utils.Helpers.FlexibleParser::TryParseDouble