User Tools

Site Tools


4rpl:commands:asfloat

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
4rpl:commands:asfloat [2021/01/08 16:01] – external edit 127.0.0.14rpl: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:
 "1.23" asfloat ->val "1.23" asfloat ->val
 </code> </code>
 +
 +Force (coerce) floating point:
 +<code 4rpl>
 +
 +4 3 div trace   # yields 1
 +
 +4 asFloat 3 div trace  # yields 1.333..
 +
 +</code>
 +
 +See also:
 +  * [[AsInt]]
 +  * [[AsString]]  
 +
 <=[[4rpl:start| Index]] <=[[4rpl:start| Index]]
  
4rpl/commands/asfloat.1610121708.txt.gz · Last modified: 2025/02/14 14:56 (external edit)