XLISP > XLISP 2.0  -  Contents  -  Reference  -  Previous | Next

*float-format*


Type:   -   system variable
Source:   -   xlprin.c

Syntax

 *float-format*

Description

*float-format* is a system variable that allows a user to specify how floating point numbers are to be printed by XLISP. The value of *float-format* should be set to one of the string expressions "%e", "%f" or "%g". These format strings are similar to C-language floating point specifications:

"%e"   -   exponential. The number is converted to decimal notation of the form:
[-]m.nnnnnnE[+-]xx
There is one leading digit. There are 6 digits after the decimal point.
 
"%f"   -   decimal. The number is converted to decimal notation of the form:
[-]mmmmmm.nnnnnn
There are as many digits before the decimal point as necessary. There are 6 digits after the decimal point.
 
"%g"   -   shortest. The number is converted to either the form of "%e" or "%f", whichever produces the shortest output string. Non-significant zeroes are not printed.

The default value for *float-format* is the string "%g".

Examples

(setq *float-format* "%e")         ; exponential notation
(print 1.0)                        ; prints 1.000000e+00
(print -9e99)                      ; prints -9.000000e+99

(setq *float-format* "%f")         ; decimal notation
(print 1.0)                        ; prints 1.000000
(print 1.0e4)                      ; prints 10000.000000
(print -999.99e-99)                ; prints -0.000000

(setq *float-format* "%g")         ; shortest notation
(print 1.0)                        ; prints 1
(print 1.0e7)                      ; prints 1e+07
(print -999.999e99)                ; prints -9.99999e+101

(setq *float-format* "SOMETHING")  ; bad notation
(print 1.0)                        ; prints SOMETHING
(setq *float-format* "%g")         ; reset to shortest notation

Note: There can be other characters put in the string, but in general, this will not produce particularly desirable behaviour. There is no error checking performed on the format string.

See the *float-format* system variable in the XLISP 2.0 manual.

  Back to Top


XLISP > XLISP 2.0  -  Contents  -  Reference  -  Previous | Next