JavaScript-1.5 Reference

JS_ValueToNumber Function

Summary

Converts a JS value to a JS double.

Syntax

JSBool JS_ValueToNumber(JSContext *cx, jsval v,
    jsdouble *dp);
NameTypeDescription
cxJSContext *Pointer to a JS context from which to derive runtime information.
vjsvalThe JS value to convert.
dpjsdouble *Pointer to the JS value that contains the converted double when the function returns.

Description

JS_ValueToNumber converts a specified JS value, v, to a JS double. The converted value is stored in the jsdouble pointed to by dp.

You can convert a JS value to a number if the JS value to convert is a JSVAL_INT, JSVAL_DOUBLE, or JSVAL_BOOLEAN. If the JS value is a JSVAL_STRING that contains numeric values and signs only, conversion also succeeds. If the JS value is a JSVAL_OBJECT, conversion is successful if the object's convert operation returns a primitive value that can be converted.

When conversion is successful, JS_ValueToNumber returns JS_TRUE. Otherwise, it reports an error and returns JS_FALSE.

See Also

Groups [ Function ]
Documents [ LXR ID Search ]
Entries [ JS_AddRoot | JS_ConvertArguments | JS_ConvertValue | JS_GetTypeName | JS_TypeOfValue | JS_ValueToBoolean | JS_ValueToFunction | JS_ValueToInt32 | JS_ValueToObject | JS_ValueToString ]

This page was generated by APIDOC