9/27/2011

alpha-3: casting to string

But quality of work can be expected only through personal satisfaction, dedication and enjoyment. In our profession, precision and perfection are not a dispensible luxury, but a simple necessity.
-Niklaus Wirth
 
You may know that in alpha-1 and 2 you can use the str subroutine to cast from an integer to a string. For example:
?number =~ "PI = ";
number = 3,141592654;
!out(~number, ~!str(number));
Output:
PI = 3,141592654
In alpha-3 str also accepts a 3th, optional argument. Notice that the above example would produce the following output in alpha-3:
PI = 3

This 3th argument is the decimal precision, and it's default value is 0. The following:

?number =~ "PI = ";
number = 3,141592654;
!out(~number, ~!str(number, 10));
 Will thus produce:
PI = 3,1415926540

No comments:

Post a Comment