to.number
to.number, function
def const pure to.number(a: i64): number
def const pure to.number(a: f64): number
def const pure to.number(a: week): number
def const pure to.number(a: month): number
Converts a to a single-precision number.
For i64 and f64, the conversion can lose precision. For week and
month, it returns the number of weeks or months since the beginning of
2001: week(2001, 1) and month(2001, 1) both convert to 0.
This is not the week or month number within the year; use
weekNum or monthNum for that.
Examples
integer = to.i64(42)
fraction = to.f64(1.5)
show summary "Converted numbers" with
to.number(integer) as "From i64" // 42
to.number(fraction) as "From f64" // 1.5
Calendar values convert to consecutive offsets:
show summary "Calendar offsets" with
to.number(week(2001, 1)) as "First week" // 0
to.number(week(2001, 2)) as "Second week" // 1
to.number(month(2001, 1)) as "January 2001" // 0
to.number(month(2001, 2)) as "February 2001" // 1
Remarks
This function is available in const expressions.
The long and double type aliases are accepted as i64 and f64,
respectively.
number cannot represent every consecutive integer beyond $2^{24}$.
Converting an i64 to number and back therefore need not reproduce the
original integer. Likewise, converting an f64 can discard significant
digits; this conversion does not merely change the display format.
Use to.number before write when exporting an i64 or
f64 value as single precision is acceptable. The original types cannot be
written directly.