|
 |

The printf function provides simple formatting, following C's
printf . It can be used in the String
Object, and in Stream writing.
% [flags][width][.prec]code
|
Printf Formatting
|
%% |
Adds the character '%' itself.
|
%s |
Format as a string.
|
%c |
Converts a character code to a character. |
%d |
Formats as a decimal integer. |
%o |
Formats as an octal integer. |
%x, %X |
Formats as a hex number. |
%f |
Formats as a fixed floating point number. |
%e, %E |
Formats as a scientific notation floating point number. |
%g, %G |
Formats as a 'nice' floating point number. |
Adds the character '%' itself.
Format as a string.
Converts a character code to a character.
String.printf("%c", 65)
|
A
|
Formats as a decimal integer.
Formats as an octal integer.
Formats as a hex number.
Formats as a fixed floating point number.
String.printf("%.2f", 4312.1294);
|
4312.13
|
Formats as a scientific notation floating point number.
String.printf("%.2e %.2E", 4312.1294, 4312.1294);
|
4.31e+03 4.31E+03
|
Formats as a 'nice' floating point number. If the
number has an exponent near 0, it formats in fixed point otherwise it
formats in scientific notation.
String.printf("%g %g %G", 3.14e-8, 4312.1294, 419e17);
|
3.14e-08 4312.13 4.19E+19
|
Copyright © 1998-2000 Caucho Technology. All rights reserved.
Last modified: Thu, 16 Sep 1999 14:56:48 -0700 (PDT)
|