﻿ RealNumber – Algosim documentation
Algosim documentation: RealNumber

# RealNumber

Converts an object to a real number.

## Syntax

• `RealNumber(X)`

• `X` is any object

## Description

If `X` is any complex number with zero imaginary part, then `RealNumber(X)` returns `X` as an object of type `RealNumber`; if the imaginary part is non-zero, an error is returned.

If `X` is a vector, matrix, list, set, or structure – in each case containing only a single element which is a number with zero imaginary part – then this number is returned in the form of a real number object.

If `X` is a string, an attempt is made to parse it as a real number. If successful, the parsed number is returned.

In all other cases, `RealNumber(X)` returns an error.

## Examples

`'((n ≔ 687), (x ≔ RealNumber(n))) @ type`
```integer
real number
```
`RealNumber(❨❨5, 9, 3, 1❩❩ ⋅ ❨❨7❩, ❨2❩, ❨4❩, ❨0❩❩)`
`65`
`RealNumber(❨❨5, 9, 3, 1❩❩ ⋅ ❨❨7❩, ❨2❩, ❨4❩, ❨i❩❩)`
`failure`
`Complex number 65 + i cannot be converted to a real number.`
`Call stack: RealNumber`
`'("3.14", "−5E6", ".57") @ RealNumber`
```3.14
−5000000
0.57
```