top banner
Gri Commands
1: Introduction
2: Simple example
3: Fancy example
4: Running Gri
5: Programming Gri
6: General Issues
7: X-Y Plots
8: Contour Plots
9: Image Plots
10: Examples
11: Handling Data
12: Gri Commands
13: Gri Extras
14: Evolution of Gri
15: Installing Gri
16: Gri Bugs
17: System Tools
18: Acknowledgments
19: License
20: Newsgroup

21: Concept Index
navigate navigate navigate navigate navigate navigate

12.45: The `sprintf' Command

`sprintf \synonym "format" .variable. [.variable. [...]]'
Write numbers into a synonym (text string). This is useful for labelling plots. `sprintf \out "a = %lf b = %.2f" .a. .b.' - Create a synonym called `\out', and print the values of the variables `.a.' and `.b.' into it. If `.a.' = 1 and `.b.' = 0.112, then `\out' will be `"a = 1 b = 0.11"' Formatting codes are as in the C programming language, eg:
%.2f  -- Use floating point with 2 decimal places.
%9.2f -- As above, but number takes 9 characters.
%e    -- Use exponential notation.
CAUTION: Variables are stored in the floating point in Gri, so you must use a format like `"%f"', not an integer code like `"%d"'.
bottom banner