ExcelFormulaParser.Engine.Excel.Functions.DoubleArgumentParser.Parse C# (CSharp) Method

Parse() public method

public Parse ( object obj ) : object
obj object
return object
        public override object Parse(object obj)
        {
            Require.That(obj).Named("argument").IsNotNull();
            if (obj is double) return obj;
            if (obj.IsNumeric()) return Convert.ToDouble(obj);
            var str = obj != null ? obj.ToString() : string.Empty;
            var decimalSeparator = CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator;
            if (decimalSeparator == ",")
            {
                str = str.Replace('.', ',');
            }
            try
            {
                return double.Parse(str);
            }
            catch (Exception e)
            {
                throw new ExcelFunctionException(str ?? "<null>" + " could not be parsed to a double", e, ExcelErrorCodes.Value);
            }
        }

Usage Example

 public void DoubleParserShouldConvertIntToDouble()
 {
     var parser = new DoubleArgumentParser();
     var result = parser.Parse(3);
     Assert.AreEqual(3d, result);
 }
All Usage Examples Of ExcelFormulaParser.Engine.Excel.Functions.DoubleArgumentParser::Parse
DoubleArgumentParser