Quirrel4.41.0

types.Float.tochar

Method on every float
pure (bool|number).tochar(): any

Converts the float to a one-character string, treating it as a character code.

Return value

A string of length 1. The float is truncated toward zero first (the same truncation tointeger does), then cast to char, so the fractional part never affects the result: (65.0).tochar() and (65.9).tochar() both give "A".

Notes

Takes no arguments. See types.Integer.tochar for the modulo-256 wraparound, which applies here too once the value is truncated.

Example

examples/types/float/tochar.nut
println("(65.0).tochar() =", (65.0).tochar())
println("(65.9).tochar() =", (65.9).tochar()) // the fractional part is dropped before the char cast
Output:
(65.0).tochar() = A
(65.9).tochar() = A

See also

tocharConverts the integer to a one-character string, treating it as a character code.
tocharConverts the bool to a one-character string, treating it as a character code.
tointegerConverts the float to an integer.
floatclass index