/*
* $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
public class PDFNumber {
- private PDFNumber() {}
-
public static String doubleOut(Double doubleDown) {
- StringBuffer p = new StringBuffer();
- if (doubleDown.doubleValue() < 0) {
- doubleDown = new Double(-doubleDown.doubleValue());
- p.append("-");
- }
- double trouble = doubleDown.doubleValue() % 1;
- if (trouble > 0.950) {
- p.append(doubleDown.intValue() + 1);
- } else if (trouble < 0.050) {
- p.append(doubleDown.intValue());
- } else {
- String doubleString = new String(doubleDown + "");
- int decimal = doubleString.indexOf(".");
- if (decimal != -1) {
- p.append(doubleString.substring(0, decimal));
-
- if ((doubleString.length() - decimal) > 6) {
- p.append(doubleString.substring(decimal, decimal + 6));
- } else {
- p.append(doubleString.substring(decimal));
- }
- } else {
- p.append(doubleString);
- }
- }
- return (p.toString());
+ return doubleOut(doubleDown.doubleValue());
}
public static String doubleOut(double doubleDown) {
-
StringBuffer p = new StringBuffer();
if (doubleDown < 0) {
doubleDown = -doubleDown;
} else if (trouble < 0.050) {
p.append((int)doubleDown);
} else {
- String doubleString = new String(doubleDown + "");
+ String doubleString = Double.toString(doubleDown);
int decimal = doubleString.indexOf(".");
if (decimal != -1) {
p.append(doubleString.substring(0, decimal));
} else if (trouble < (5.0 / (Math.pow(10.0, dec)))) {
p.append((int)doubleDown);
} else {
- String doubleString = new String(doubleDown + "");
+ String doubleString = Double.toString(doubleDown);
int decimal = doubleString.indexOf(".");
if (decimal != -1) {
p.append(doubleString.substring(0, decimal));