SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
PrintfFormat.java
1/*
2 * Class: PrintfFormat
3 * Description:
4 * Environment: Java
5 * Software: SSJ
6 * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal
7 * Organization: DIRO, Universite de Montreal
8 * @author
9 * @since
10 *
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 */
25package umontreal.ssj.util;
26
27import java.text.NumberFormat;
28import java.text.DecimalFormat;
29import java.text.DecimalFormatSymbols;
30import java.util.Locale;
31import java.util.Formatter;
32
45public class PrintfFormat implements CharSequence, Appendable {
46 private static NumberFormat nf = NumberFormat.getInstance(Locale.US);
47 private static DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.US);
48 private static final int NDEC = 50;
49 private static DecimalFormat[] dfe = new DecimalFormat[NDEC + 1];
50 private static DecimalFormat[] dfg = new DecimalFormat[NDEC + 1];
51 private StringBuffer sb;
52 /*
53 * private static void round (int b, StringBuffer num) { // round a real number
54 * up if it is >= 0.5 // base is b
55 *
56 * // round up the fractional part int j = num.length() - 1; String bm1 =
57 * String.valueOf (b - 1); while (j >= 0 && num.charAt(j) == bm1.charAt(0)) {
58 * num.deleteCharAt(j); j--; }
59 *
60 * char c; if (j < 0) return; if (num.charAt(j) != '.') { c = num.charAt(j);
61 * ++c; num.replace(j, j + 1, Character.toString(c)); return; }
62 *
63 * // round up the integral part j--; while (j >= 0 && num.charAt(j) ==
64 * bm1.charAt(0)) { num.replace(j, j + 1, "0"); j--; }
65 *
66 * if (j < 0 || num.charAt(j) == '-') { num.insert( j + 1, '1'); } else if
67 * (num.charAt(j) == ' ') { num.replace(j, j + 1, "1"); } else { c =
68 * num.charAt(j); ++c; num.replace(j, j + 1, Character.toString(c)); } }
69 */
70
74
79 public static final String NEWLINE = System.getProperty("line.separator");
80
84 public static final String LINE_SEPARATOR = System.getProperty("line.separator");
85
89
93 public PrintfFormat() {
94 sb = new StringBuffer();
95 }
96
102 public PrintfFormat(int length) {
103 sb = new StringBuffer(length);
104 }
105
111 public PrintfFormat(String str) {
112 sb = new StringBuffer(str);
113 }
114
121 public PrintfFormat append(String str) {
122 sb.append(str);
123 return this;
124 }
125
135 public PrintfFormat append(int fieldwidth, String str) {
136 sb.append(s(fieldwidth, str));
137 return this;
138 }
139
146 public PrintfFormat append(double x) {
147 sb.append(x);
148 return this;
149 }
150
159 public PrintfFormat append(int fieldwidth, double x) {
160 sb.append(f(fieldwidth, x));
161 return this;
162 }
163
174 public PrintfFormat append(int fieldwidth, int precision, double x) {
175 sb.append(f(fieldwidth, precision, x));
176 return this;
177 }
178
185 public PrintfFormat append(int x) {
186 sb.append(x);
187 return this;
188 }
189
198 public PrintfFormat append(int fieldwidth, int x) {
199 sb.append(d(fieldwidth, x));
200 return this;
201 }
202
209 public PrintfFormat append(long x) {
210 sb.append(x);
211 return this;
212 }
213
222 public PrintfFormat append(int fieldwidth, long x) {
223 sb.append(d(fieldwidth, x));
224 return this;
225 }
226
237 public PrintfFormat append(int fieldwidth, int accuracy, int precision, double x) {
238 sb.append(format(fieldwidth, accuracy, precision, x));
239 return this;
240 }
241
248 public PrintfFormat append(char c) {
249 sb.append(c);
250 return this;
251 }
252
256 public void clear() {
257 sb.setLength(0);
258 }
259
265 public StringBuffer getBuffer() {
266 return sb;
267 }
268
274 public String toString() {
275 return sb.toString();
276 }
277
285 public static String s(String str) {
286 if (str == null)
287 return "null";
288 else
289 return str;
290 }
291
305 public static String s(int fieldwidth, String str) {
306 if (str == null)
307 return s(fieldwidth, "null");
308
309 int fw = Math.abs(fieldwidth);
310 if (str.length() < fw) {
311 // We have to pad with spaces
312 StringBuffer buf = new StringBuffer();
313 int sl = str.length();
314 for (int i = 0; i < fw - sl; i++)
315 buf.append(' ');
316 // Add the spaces before or after
317 return fieldwidth >= 0 ? buf.toString() + str : str + buf.toString();
318 } else
319 return str;
320 }
321
325
332 public static String d(long x) {
333 return d(0, 1, x);
334 }
335
343 public static String d(int fieldwidth, long x) {
344 return d(fieldwidth, 1, x);
345 }
346
359 public static String d(int fieldwidth, int precision, long x) {
360 if (precision < 0)
361 throw new IllegalArgumentException("precision must " + "not be negative.");
362 if (precision == 0 && x == 0)
363 return s(fieldwidth, "");
364
365 nf.setGroupingUsed(false);
366 nf.setMinimumIntegerDigits(precision);
367 nf.setMaximumFractionDigits(0); // will also set the min to 0
368 return s(fieldwidth, nf.format(x));
369 }
370
377 public static String format(long x) {
378 return d(0, 1, x);
379 }
380
390 public static String format(int fieldwidth, long x) {
391 return d(fieldwidth, 1, x);
392 }
393
401 public static String formatBase(int b, long x) {
402 return formatBase(0, b, x);
403 }
404
414 public static String formatBase(int fieldwidth, int b, long x) {
415 boolean neg = false; // insert a '-' if true
416 if (b < 2 || b > 10)
417 throw new IllegalArgumentException("base must be between 2 and 10.");
418
419 if (x < 0) {
420 neg = true;
421 x = -x;
422 } else {
423 if (x == 0)
424 return "0";
425
426 neg = false;
427 }
428 StringBuffer sb = new StringBuffer();
429 while (x > 0) {
430 sb.insert(0, x % b);
431 x = x / b;
432 }
433 if (neg)
434 sb.insert(0, '-');
435 return s(fieldwidth, sb.toString());
436 }
437
441
445
452 public static String E(double x) {
453 return E(0, 6, x);
454 }
455
463 public static String E(int fieldwidth, double x) {
464 return E(fieldwidth, 6, x);
465 }
466
480 public static String E(int fieldwidth, int precision, double x) {
481 if (precision < 0)
482 throw new IllegalArgumentException("precision must " + "not be negative.");
483 if (Double.isNaN(x))
484 return s(fieldwidth, "NaN");
485 if (Double.isInfinite(x))
486 return s(fieldwidth, (x < 0 ? "-" : "") + "Infinite");
487
488 DecimalFormat df;
489 if (precision >= dfe.length || dfe[precision] == null) {
490 // We need to create one pattern per precision value
491 StringBuffer pattern = new StringBuffer("0.");
492 for (int i = 0; i < precision; i++)
493 pattern.append("0");
494 pattern.append("E00");
495 df = new DecimalFormat(pattern.toString(), dfs);
496 df.setGroupingUsed(false);
497 if (precision < dfe.length)
498 dfe[precision] = df;
499 } else
500 df = dfe[precision];
501 String res = df.format(x);
502 // DecimalFormat doesn't add the + sign before the value of
503 // the exponent.
504 int exppos = res.indexOf('E');
505 if (exppos != -1 && res.charAt(exppos + 1) != '-')
506 res = res.substring(0, exppos + 1) + "+" + res.substring(exppos + 1);
507 return s(fieldwidth, res);
508 }
509
516 public static String e(double x) {
517 return e(0, 6, x);
518 }
519
527 public static String e(int fieldwidth, double x) {
528 return e(fieldwidth, 6, x);
529 }
530
540 public static String e(int fieldwidth, int precision, double x) {
541 String res = E(fieldwidth, precision, x);
542 int exppos = res.indexOf('E');
543 return exppos == -1 ? res : res.substring(0, exppos) + 'e' + res.substring(exppos + 1);
544 }
545
552 public static String f(double x) {
553 return f(0, 6, x);
554 }
555
563 public static String f(int fieldwidth, double x) {
564 return f(fieldwidth, 6, x);
565 }
566
580 public static String f(int fieldwidth, int precision, double x) {
581 if (precision < 0)
582 throw new IllegalArgumentException("precision must " + "not be negative.");
583 if (Double.isNaN(x))
584 return s(fieldwidth, "NaN");
585 if (Double.isInfinite(x))
586 return s(fieldwidth, (x < 0 ? "-" : "") + "Infinite");
587
588 nf.setGroupingUsed(false);
589 nf.setMinimumIntegerDigits(1);
590 nf.setMinimumFractionDigits(precision);
591 nf.setMaximumFractionDigits(precision);
592 return s(fieldwidth, nf.format(x));
593 }
594
601 public static String G(double x) {
602 return G(0, 6, x);
603 }
604
612 public static String G(int fieldwidth, double x) {
613 return G(fieldwidth, 6, x);
614 }
615
630 public static String G(int fieldwidth, int precision, double x) {
631 if (precision < 0)
632 throw new IllegalArgumentException("precision must " + "not be negative.");
633 if (precision == 0)
634 precision = 1;
635
636 if (Double.isNaN(x))
637 return s(fieldwidth, "NaN");
638 if (Double.isInfinite(x))
639 return s(fieldwidth, (x < 0 ? "-" : "") + "Infinite");
640
641 // Calculate the scientific notation format.
642 // We cannot use E because it can make trailing zeros
643 // that must be removed afterward.
644 DecimalFormat df;
645 if (precision >= dfg.length || dfg[precision] == null) {
646 StringBuffer pattern = new StringBuffer("0.");
647 for (int i = 0; i < (precision - 1); i++)
648 pattern.append("#"); // Do not show trailing zeros
649 pattern.append("E00");
650 df = new DecimalFormat(pattern.toString(), dfs);
651 df.setGroupingUsed(false);
652 if (precision < dfg.length)
653 dfg[precision] = df;
654 } else
655 df = dfg[precision];
656 String res = df.format(x);
657
658 int exppos = res.indexOf('E');
659 if (exppos == -1)
660 return res;
661 int expval = Integer.parseInt(res.substring(exppos + 1));
662 if (expval < -4 || expval >= precision) {
663 // add the plus sign for the exponent if necessary.
664 if (res.charAt(exppos + 1) != '-')
665 return s(fieldwidth, res.substring(0, exppos + 1) + "+" + res.substring(exppos + 1));
666 else
667 return s(fieldwidth, res);
668 }
669
670 // Calculate the decimal notation format
671 nf.setGroupingUsed(false);
672 nf.setMinimumIntegerDigits(1);
673 nf.setMinimumFractionDigits(0);
674 // We need the number of digits after the decimal point to
675 // to get precisions significant digits.
676 // The integer part of x contains at most precision digits.
677 // If that was not true, expval would be greater than precision.
678 // If expval=0, we have a number of the form 1.234...
679 // To have precisions significant digits, we need precision-1 digits.
680 // If expval<0, x<1 and we need -expval additionnal
681 // decimal digits.
682 // If expval>0, we need less decimal digits.
683 nf.setMaximumFractionDigits(precision - expval - 1);
684 res = nf.format(x);
685 return s(fieldwidth, res);
686 }
687
694 public static String g(double x) {
695 return g(0, 6, x);
696 }
697
705 public static String g(int fieldwidth, double x) {
706 return g(fieldwidth, 6, x);
707 }
708
717 public static String g(int fieldwidth, int precision, double x) {
718 String res = G(fieldwidth, precision, x);
719 int exppos = res.indexOf('E');
720 return exppos == -1 ? res : res.substring(0, exppos) + 'e' + res.substring(exppos + 1);
721 }
722
740 public static String format(int fieldwidth, int accuracy, int precision, double x) {
741 if (Double.isNaN(x))
742 return s(fieldwidth, "NaN");
743 if (Double.isInfinite(x))
744 return s(fieldwidth, (x < 0 ? "-" : "") + "Infinite");
745
746 if (canUseDecimalNotation(fieldwidth, accuracy, precision, x))
747 return f(fieldwidth, accuracy, x);
748 // Use scientific notation
749 else {
750 String S = E(fieldwidth, precision - 1, x);
751 return processExp(S);
752 }
753 }
754
755 private static boolean canUseDecimalNotation(int fieldwidth, int accuracy, int precision, double x) {
756 // Le nombre de positions occupees par la partie entiere de x
757 int PosEntier = 0;
758 // Le nombre de chiffres significatifs avant le point
759 int EntierSign;
760 // La position de l'exposant dans le string S et la longueur de S
761 int Neg = 0;
762
763 if (x == 0.0)
764 EntierSign = 1;
765 else {
766 EntierSign = PosEntier = (int) Math.floor(Math.log10(Math.abs(x)) + 1);
767 if (x < 0.0)
768 Neg = 1;
769 }
770 if (EntierSign <= 0)
771 PosEntier = 1;
772 return x == 0.0 || (((EntierSign + accuracy) >= precision) && (fieldwidth >= (PosEntier + accuracy + Neg + 1)));
773 }
774
775 private static int getMinAccuracy(double x) {
776 if (Math.abs(x) >= 1 || x == 0)
777 return 0;
778 else
779 return -(int) Math.floor(Math.log10(Math.abs(x)));
780 }
781
782 private static String processExp(String s) {
783 int p = s.indexOf("E+0");
784 if (p == -1)
785 p = s.indexOf("E-0");
786
787 // remove the 0 in E-0 and in E+0
788 if (p != -1)
789 s = " " + s.substring(0, p + 2) + s.substring(p + 3);
790
791 p = s.indexOf(".E");
792 if (p != -1)
793 s = " " + s.substring(0, p) + s.substring(p + 1);
794 return s;
795 }
796
808 public static String format(Locale locale, int fieldwidth, int accuracy, int precision, double x) {
809 Formatter fmt = new Formatter(locale);
810 if (Double.isNaN(x))
811 return fmt.format("%" + fieldwidth + "s", "NaN").toString();
812 if (Double.isInfinite(x))
813 return fmt.format("%" + fieldwidth + "s", (x < 0 ? "-" : "") + "Infinite").toString();
814
815 if (canUseDecimalNotation(fieldwidth, accuracy, precision, x))
816 return fmt.format("%" + fieldwidth + "." + accuracy + "f", x).toString();
817 // Use scientific notation
818 else {
819 String S = fmt.format("%" + fieldwidth + "." + (precision - 1) + "E", x).toString();
820 return processExp(S);
821 }
822 }
823
838 public static String formatBase(int fieldwidth, int accuracy, int b, double x) {
839 if (Double.isNaN(x))
840 return s(fieldwidth, "NaN");
841 if (Double.isInfinite(x))
842 return s(fieldwidth, (x < 0 ? "-" : "") + "Infinite");
843 if (0. == x || -0. == x)
844 return s(fieldwidth, "0");
845 if (Math.abs(x) >= Num.TWOEXP[63])
846 throw new UnsupportedOperationException(" |x| >= 2^63");
847
848 long n = (long) x;
849 String mant = formatBase(-1, b, n);
850 if (n == x)
851 return s(fieldwidth, mant);
852 if (n == 0) {
853 if (x < 0) {
854 mant = "-0";
855 } else
856 mant = "0";
857 }
858 // round before printing
859 if (x > 0)
860 x += 0.5 * Math.pow(b, -accuracy - 1);
861 else if (x < 0)
862 x -= 0.5 * Math.pow(b, -accuracy - 1);
863 x -= n;
864 if (x < 0)
865 x = -x;
866
867 StringBuffer frac = new StringBuffer(".");
868 long y;
869 int j;
870 for (j = 0; j < accuracy; ++j) {
871 x *= b;
872 y = (long) x;
873 frac.append(y);
874 x -= y;
875 if (x == 0.)
876 break;
877 }
878
879 StringBuffer number = new StringBuffer(mant);
880 number.append(frac);
881
882 // remove trailing spaces and 0
883 j = number.length() - 1;
884 while (j > 0 && (number.charAt(j) == '0' || number.charAt(j) == ' ')) {
885 number.deleteCharAt(j);
886 j--;
887 }
888
889 return s(fieldwidth, number.toString());
890 }
891
892 // Interface CharSequence
893 public char charAt(int index) {
894 return sb.charAt(index);
895 }
896
897 public int length() {
898 return sb.length();
899 }
900
901 public CharSequence subSequence(int start, int end) {
902 return sb.subSequence(start, end);
903 }
904
905 // Interface Appendable
906 public Appendable append(CharSequence csq) {
907 return sb.append(csq);
908 }
909
910 public Appendable append(CharSequence csq, int start, int end) {
911 return sb.append(csq, start, end);
912 }
913
917
921
946 public static void formatWithError(int fieldwidth, int fieldwidtherr, int accuracy, int precision, double x,
947 double error, String[] res) {
948 if (res.length != 2)
949 throw new IllegalArgumentException("The given res array must contain two elements");
950 if (Double.isNaN(x)) {
951 res[0] = s(fieldwidth, "NaN");
952 res[1] = s(fieldwidtherr, "");
953 return;
954 }
955 if (Double.isInfinite(x)) {
956 res[0] = s(fieldwidth, (x < 0 ? "-" : "") + "Infinite");
957 res[1] = s(fieldwidtherr, "");
958 return;
959 }
960 if (accuracy < 0)
961 accuracy = 0;
962
963 if (canUseDecimalNotation(fieldwidth, accuracy, precision, x)) {
964 res[0] = f(fieldwidth, accuracy, x);
965 res[1] = f(fieldwidtherr, accuracy, error);
966 }
967 // Use scientific notation
968 else {
969 res[0] = processExp(E(fieldwidth, precision - 1, x));
970 int xExp = x == 0 ? 0 : (int) Math.floor(Math.log10(Math.abs(x)));
971 int errorExp = error == 0 ? 0 : (int) Math.floor(Math.log10(Math.abs(error)));
972 int errorPrecision = precision - 1 - (xExp - errorExp);
973 if (errorPrecision < 0)
974 errorPrecision = 0;
975 res[1] = processExp(E(fieldwidtherr, errorPrecision, error));
976 }
977 }
978
996 public static void formatWithError(int fieldwidth, int fieldwidtherr, int precision, double x, double error,
997 String[] res) {
998 int accuracy = getMinAccuracy(error);
999 if (!canUseDecimalNotation(fieldwidth, accuracy, precision, x)) {
1000 int posEntier = (int) Math.floor(Math.log(Math.abs(x)) / Math.log(10) + 1);
1001 if (posEntier < 0)
1002 posEntier = 1;
1003 int newAccuracy = precision - posEntier;
1004 if (canUseDecimalNotation(fieldwidth, newAccuracy, precision, x))
1005 accuracy = newAccuracy;
1006 }
1007 formatWithError(fieldwidth, fieldwidtherr, accuracy, precision, x, error, res);
1008 }
1009
1026 public static void formatWithError(Locale locale, int fieldwidth, int fieldwidtherr, int accuracy, int precision,
1027 double x, double error, String[] res) {
1028 if (res.length != 2)
1029 throw new IllegalArgumentException("The given res array must contain two elements");
1030 Formatter fmt = new Formatter(locale);
1031 Formatter fmtErr = new Formatter(locale);
1032 if (Double.isNaN(x)) {
1033 res[0] = fmt.format("%" + fieldwidth + "s", "NaN").toString();
1034 res[1] = fmtErr.format("%" + fieldwidtherr + "s", "").toString();
1035 return;
1036 }
1037 if (Double.isInfinite(x)) {
1038 res[0] = fmt.format("%" + fieldwidth + "s", (x < 0 ? "-" : "") + "Infinite").toString();
1039 res[1] = fmtErr.format("%" + fieldwidtherr + "s", "").toString();
1040 return;
1041 }
1042 if (accuracy < 0)
1043 accuracy = 0;
1044
1045 if (canUseDecimalNotation(fieldwidth, accuracy, precision, x)) {
1046 res[0] = fmt.format("%" + fieldwidth + "." + accuracy + "f", x).toString();
1047 res[1] = fmtErr.format("%" + fieldwidtherr + "." + accuracy + "f", error).toString();
1048 }
1049 // Use scientific notation
1050 else {
1051 res[0] = processExp(fmt.format("%" + fieldwidth + "." + (precision - 1) + "E", x).toString());
1052 int xExp = x == 0 ? 0 : (int) Math.floor(Math.log10(Math.abs(x)));
1053 int errorExp = error == 0 ? 0 : (int) Math.floor(Math.log10(Math.abs(error)));
1054 int errorPrecision = precision - 1 - (xExp - errorExp);
1055 if (errorPrecision < 0)
1056 errorPrecision = 0;
1057 res[1] = processExp(fmtErr.format("%" + fieldwidtherr + "." + errorPrecision + "E", error).toString());
1058 }
1059 }
1060
1075 public static void formatWithError(Locale locale, int fieldwidth, int fieldwidtherr, int precision, double x,
1076 double error, String[] res) {
1077 int accuracy = getMinAccuracy(error);
1078 if (!canUseDecimalNotation(fieldwidth, accuracy, precision, x)) {
1079 int posEntier = (int) Math.floor(Math.log(Math.abs(x)) / Math.log(10) + 1);
1080 if (posEntier < 0)
1081 posEntier = 1;
1082 int newAccuracy = precision - posEntier;
1083 if (canUseDecimalNotation(fieldwidth, newAccuracy, precision, x))
1084 accuracy = newAccuracy;
1085 }
1086 formatWithError(locale, fieldwidth, fieldwidtherr, accuracy, precision, x, error, res);
1087 }
1088
1089}
1090
This class provides various constants and methods to compute numerical quantities such as factorials,...
Definition Num.java:35
static final double TWOEXP[]
Contains the precomputed positive powers of 2.
Definition Num.java:170
String toString()
Converts the buffer into a String.
static void formatWithError(Locale locale, int fieldwidth, int fieldwidtherr, int accuracy, int precision, double x, double error, String[] res)
This method is equivalent to formatWithError(int,int,int,double,double,String[]), except that it form...
PrintfFormat append(int fieldwidth, int precision, double x)
Uses the f(int,int,double) static method to append x to the buffer.
static void formatWithError(int fieldwidth, int fieldwidtherr, int precision, double x, double error, String[] res)
Stores a string containing x into res[0], and a string containing error into res[1],...
static String formatBase(int fieldwidth, int b, long x)
Converts the integer x to a String representation in base b.
PrintfFormat()
Constructs a new buffer object containing an empty string.
static String format(Locale locale, int fieldwidth, int accuracy, int precision, double x)
This method is equivalent to format(int,int,int,double), except it formats the given value for the lo...
static String e(int fieldwidth, double x)
Same as e(fieldwidth, 6, x).
static String e(double x)
Same as e(0, 6, x).
PrintfFormat append(int fieldwidth, double x)
Uses the f(int,double) static method to append x to the buffer.
static String G(int fieldwidth, double x)
Same as G(fieldwidth, 6, x).
static String s(String str)
Same as s(0, str).
static String E(int fieldwidth, int precision, double x)
Formats a double-precision number x like E in C printf.
StringBuffer getBuffer()
Returns the StringBuffer associated with that object.
static String format(int fieldwidth, int accuracy, int precision, double x)
Returns a String containing x.
static String e(int fieldwidth, int precision, double x)
The same as E, except that ‘e’ is used as the exponent character instead of ‘E’.
static String d(long x)
Same as d(0, 1, x).
static void formatWithError(int fieldwidth, int fieldwidtherr, int accuracy, int precision, double x, double error, String[] res)
Stores a string containing x into res[0], and a string containing error into res[1],...
static String g(int fieldwidth, double x)
Same as g(fieldwidth, 6, x).
PrintfFormat append(String str)
Appends str to the buffer.
static String formatBase(int b, long x)
Same as formatBase(0, b, x).
PrintfFormat append(int fieldwidth, long x)
Uses the d(int,long) static method to append x to the buffer.
PrintfFormat append(int x)
Appends x to the buffer.
static String f(double x)
Same as f(0, 6, x).
static String d(int fieldwidth, int precision, long x)
Formats the long integer x into a string like d in the C printf function.
static final String NEWLINE
End-of-line symbol or line separator.
PrintfFormat append(double x)
Appends x to the buffer.
static String d(int fieldwidth, long x)
Same as d(fieldwidth, 1, x).
PrintfFormat(int length)
Constructs a new buffer object with an initial capacity of length.
static String G(int fieldwidth, int precision, double x)
Formats the double-precision x into a string like G in C printf.
PrintfFormat append(int fieldwidth, int accuracy, int precision, double x)
Uses the format(int,int,int,double) static method with the same four arguments to append x to the buf...
void clear()
Clears the contents of the buffer.
static String E(int fieldwidth, double x)
Same as E(fieldwidth, 6, x).
PrintfFormat append(int fieldwidth, int x)
Uses the d(int,long) static method to append x to the buffer.
static String format(long x)
Same as d(0, 1, x).
static String G(double x)
Same as G(0, 6, x).
static String s(int fieldwidth, String str)
Formats the string str like the s in the C printf function.
static final String LINE_SEPARATOR
End-of-line symbol or line separator.
static String E(double x)
Same as E(0, 6, x).
static void formatWithError(Locale locale, int fieldwidth, int fieldwidtherr, int precision, double x, double error, String[] res)
This method is equivalent to formatWithError(int,int,int,double,double,String[]), except that it form...
static String f(int fieldwidth, int precision, double x)
Formats the double-precision x into a string like f in C printf.
static String formatBase(int fieldwidth, int accuracy, int b, double x)
Converts to a String representation in base using formatting similar to the methods.
PrintfFormat(String str)
Constructs a new buffer object containing the initial string str.
static String g(int fieldwidth, int precision, double x)
The same as G, except that ‘e’ is used in the scientific notation.
static String g(double x)
Same as g(0, 6, x).
PrintfFormat append(char c)
Appends a single character to the buffer.
PrintfFormat append(long x)
Appends x to the buffer.
PrintfFormat append(int fieldwidth, String str)
Uses the s(int,String) static method to append str to the buffer.
static String format(int fieldwidth, long x)
Converts a long integer to a String with a minimum length of fieldwidth, the result is right-padded w...
static String f(int fieldwidth, double x)
Same as f(fieldwidth, 6, x).