This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
4rpl:commands:asfloat [2021/01/08 16:01] – external edit 127.0.0.1 | 4rpl:commands:asfloat [2025/02/14 14:57] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 7: | Line 7: | ||
===== Description ===== | ===== Description ===== | ||
Converts an item on the stack to a floating point number and pushes it back onto the stack. | Converts an item on the stack to a floating point number and pushes it back onto the stack. | ||
+ | |||
+ | This is useful if one needs a floating-point result from operating on two integers. By default, 4RPL may return an integer value after an arithmetic operation on two integers, but a floating-point value might be desirable. | ||
===== Examples ===== | ===== Examples ===== | ||
Line 12: | Line 14: | ||
" | " | ||
</ | </ | ||
+ | |||
+ | Force (coerce) floating point: | ||
+ | <code 4rpl> | ||
+ | |||
+ | 4 3 div trace # yields 1 | ||
+ | |||
+ | 4 asFloat 3 div trace # yields 1.333.. | ||
+ | |||
+ | </ | ||
+ | |||
+ | See also: | ||
+ | * [[AsInt]] | ||
+ | * [[AsString]] | ||
+ | |||
< | < | ||