---
title: toNumber()
framework: javascriptcore
role: symbol
role_heading: Instance Method
path: javascriptcore/jsvalue/tonumber()
---

# toNumber()

Converts the JavaScript value to a NSNumber object.

## Declaration

```swift
func toNumber() -> NSNumber!
```

## Return Value

Return Value A NSNumber object encapsulating the native representation of the value.

## Discussion

Discussion If the value represents a Boolean value, the resulting NSNumber object is created as with the numberWithBool: method. Otherwise, this method uses JavaScript type coercion to convert the value to a JavaScript numeric value and creates a NSNumber object wrapping the result.

## See Also

### Reading and Converting JavaScript Values

- [toObject()](javascriptcore/jsvalue/toobject().md)
- [toObjectOf(_:)](javascriptcore/jsvalue/toobjectof(_:).md)
- [toBool()](javascriptcore/jsvalue/tobool().md)
- [toDouble()](javascriptcore/jsvalue/todouble().md)
- [toInt32()](javascriptcore/jsvalue/toint32().md)
- [toUInt32()](javascriptcore/jsvalue/touint32().md)
- [toString()](javascriptcore/jsvalue/tostring().md)
- [toDate()](javascriptcore/jsvalue/todate().md)
- [toArray()](javascriptcore/jsvalue/toarray().md)
- [toDictionary()](javascriptcore/jsvalue/todictionary().md)
- [toPoint()](javascriptcore/jsvalue/topoint().md)
- [toRange()](javascriptcore/jsvalue/torange().md)
- [toRect()](javascriptcore/jsvalue/torect().md)
- [toSize()](javascriptcore/jsvalue/tosize().md)
