Skip to content

Commit 0c4c70a

Browse files
corymickelsonmhdawson
authored andcommitted
doc: initial pass on number docs
PR-URL: #185 Reviewed-By: Michael Dawson <[email protected]>
1 parent b639620 commit 0c4c70a

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

doc/number.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Number
2+
3+
A Javascript number value.
4+
## Methods
5+
6+
7+
### Constructor
8+
9+
```cpp
10+
Napi::Number::New(Napi::Env env, double value);
11+
```
12+
- `[in] env`: The `napi_env` Environment
13+
- `[in] value`: The value the Javascript Number will contain
14+
15+
```cpp
16+
Napi::Number();
17+
```
18+
returns a new empty Javascript Number
19+
20+
You can easily cast a Javascript number to one of:
21+
- int32_t
22+
- uint32_t
23+
- int64_t
24+
- float
25+
- double
26+
27+
The following shows an example of casting a number to an uint32_t value.
28+
29+
```cpp
30+
uint32_t operatorVal = Number::New(Env(), 10.0); // Number to unsigned 32 bit integer
31+
// or
32+
auto instanceVal = info[0].As<Number>().Uint32Value();
33+
```

0 commit comments

Comments
 (0)