User Tools

Site Tools


4rpl:commands:asfloat

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
4rpl:commands:asfloat [2022/04/13 09:12] – cross-ref Karsten754rpl: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 =====
 <code 4rpl> <code 4rpl>
 "1.23" asfloat ->val "1.23" asfloat ->val
 +</code>
 +
 +Force (coerce) floating point:
 +<code 4rpl>
 +
 +4 3 div trace   # yields 1
 +
 +4 asFloat 3 div trace  # yields 1.333..
 +
 </code> </code>
  
4rpl/commands/asfloat.1649841153.txt.gz · Last modified: 2025/02/14 14:56 (external edit)