// Return a double representation of JSValue. // Boolean is converted to 0.0 or 1.0. // Null, Object, and Array are 0. public double AsDouble() { switch (Type) { case JSValueType.String: return(JSConverter.ToJSNumber(StringValue)); case JSValueType.Boolean: return(BooleanValue ? 1.0 : 0.0); case JSValueType.Int64: return(Int64Value); case JSValueType.Double: return(DoubleValue); default: return(0); } }
// Return an Int64 representation of JSValue. // String is converted to double first before converting to Int64. // Boolean is converted to 0 or 1. // Null, Object, and Array are 0. public long AsInt64() { switch (Type) { case JSValueType.String: return(JSConverter.ToInt64(JSConverter.ToJSNumber(StringValue))); case JSValueType.Boolean: return(BooleanValue ? 1 : 0); case JSValueType.Int64: return(Int64Value); case JSValueType.Double: return(JSConverter.ToInt64(DoubleValue)); default: return(0); } }
// Return a Double representation of JSValue. It is equivalent to JavaScript Number(value) result. public double AsJSNumber() { switch (Type) { case JSValueType.Object: case JSValueType.Array: case JSValueType.String: return(JSConverter.ToJSNumber(AsJSString())); case JSValueType.Boolean: return(BooleanValue ? 1 : 0); case JSValueType.Int64: return(Int64Value); case JSValueType.Double: return(DoubleValue); default: return(0); } }