Datatypes conversion: 


Red documentation

action! to

Converts one datatype! to another, e.g. an integer! to a string! , a float! to an integer! and even a string! to a number!.

>> to integer! 3.4
== 3

>> to float! 23
== 23.0

>> to string! 23.2
== "23.2"

>> to integer! "34"
== 34


function! to-time

Converts values to time! datatype.

>> to-time [22 55 48]
== 22:55:48

>> to-time [22 65 70]
== 23:06:10

>> to-time "11:15"
== 11:15:00

native! as-pair

Converts two integer! or float! into pair!. Note that this is not exactly a "conversion" as we are creating a new value from two values that may even be of different datatypes, as is the case when we "join" a float! and an integer! into a pair!.

>> as-pair 11 53
== 11x53

>> as-pair 3.2 5.67
== 3x5

>> as-pair 88 12.7
== 88x12

function! to-binary

Convert to binary! value. It seems that it's not a base converter, but a datatype converter.


>> to-binary 8
== #{00000008}

>> to-binary 33
== #{00000021}


< Previous topic                                                                                          Next topic >