Napi::Number
class is a representation of the JavaScript Number
object. The
Napi::Number
class inherits its behavior from Napi::Value
class
(for more info see Napi::Value
)
Creates a new empty instance of a Napi::Number
object.
Napi::Number();
Returns a new empty Napi::Number
object.
Creates a new instance of a Napi::Number
object.
Napi::Number(napi_env env, napi_value value);
[in] env
: Thenapi_env
environment in which to construct theNapi::Number
object.[in] value
: The JavaScript value holding a number.
Returns a non-empty Napi::Number
object.
Creates a new instance of a Napi::Number
object.
Napi::Number Napi::Number::New(napi_env env, double value);
[in] env
: Thenapi_env
environment in which to construct theNapi::Number
object.[in] value
: The C++ primitive from which to instantiate theNapi::Number
.
Creates a new instance of a Napi::Number
object.
Converts a Napi::Number
value to a int32_t
primitive type.
Napi::Number::Int32Value() const;
Returns the int32_t
primitive type of the corresponding Napi::Number
object.
Converts a Napi::Number
value to a uint32_t
primitive type.
Napi::Number::Uint32Value() const;
Returns the uint32_t
primitive type of the corresponding Napi::Number
object.
Converts a Napi::Number
value to a int64_t
primitive type.
Napi::Number::Int64Value() const;
Returns the int64_t
primitive type of the corresponding Napi::Number
object.
Converts a Napi::Number
value to a float
primitive type.
Napi::Number::FloatValue() const;
Returns the float
primitive type of the corresponding Napi::Number
object.
Converts a Napi::Number
value to a double
primitive type.
Napi::Number::DoubleValue() const;
Returns the double
primitive type of the corresponding Napi::Number
object.
The Napi::Number
class contains a set of operators to easily cast JavaScript
Number
object to one of the following primitive types:
int32_t
uint32_t
int64_t
float
double
Converts a Napi::Number
value to a int32_t
primitive.
Napi::Number::operator int32_t() const;
Returns the int32_t
primitive type of the corresponding Napi::Number
object.
Converts a Napi::Number
value to a uint32_t
primitive type.
Napi::Number::operator uint32_t() const;
Returns the uint32_t
primitive type of the corresponding Napi::Number
object.
Converts a Napi::Number
value to a int64_t
primitive type.
Napi::Number::operator int64_t() const;
Returns the int64_t
primitive type of the corresponding Napi::Number
object.
Converts a Napi::Number
value to a float
primitive type.
Napi::Number::operator float() const;
Returns the float
primitive type of the corresponding Napi::Number
object.
Converts a Napi::Number
value to a double
primitive type.
Napi::Number::operator double() const;
Returns the double
primitive type of the corresponding Napi::Number
object.
The following shows an example of casting a number to an uint32_t
value.
uint32_t operatorVal = Napi::Number::New(Env(), 10.0); // Number to unsigned 32 bit integer
// or
auto instanceVal = info[0].As<Napi::Number>().Uint32Value();