You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mo...@apache.org on 2001/12/04 13:59:40 UTC

cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/runtime BasisLibrary.java

morten      01/12/04 04:59:40

  Modified:    java/src/org/apache/xalan/xsltc/runtime BasisLibrary.java
  Log:
  Updated the realToString() method in the runtime library to always output
  numbers on decimal form (and not on Java's "computerized scientific notation."
  PR:		bugzilla 4199
  Obtained from:	n/a
  Submitted by:	morten@xml.apache.org
  Reviewed by:	morten@xml.apache.org
  
  Revision  Changes    Path
  1.32      +19 -6     xml-xalan/java/src/org/apache/xalan/xsltc/runtime/BasisLibrary.java
  
  Index: BasisLibrary.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/BasisLibrary.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- BasisLibrary.java	2001/11/29 12:51:31	1.31
  +++ BasisLibrary.java	2001/12/04 12:59:40	1.32
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: BasisLibrary.java,v 1.31 2001/11/29 12:51:31 morten Exp $
  + * @(#)$Id: BasisLibrary.java,v 1.32 2001/12/04 12:59:40 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -825,17 +825,30 @@
   	}
       }
   
  +    private static double lowerBounds = 0.001;
  +    private static double upperBounds = 10000000;
  +    private static DecimalFormat defaultFormatter = new DecimalFormat();
  +    private static String defaultPattern = "####################.#########";
  +
       /**
        * Utility function: used in RealType to convert a real to a string.
        * Removes the decimal if null.
        */
       public static String realToString(double d) {
  -	final String result = Double.toString(d);
  -	final int length = result.length();
  -	if (result.charAt(length-2) == '.' && result.charAt(length-1) == '0') {
  -	    return result.substring(0, length-2);
  +	final double m = Math.abs(d);
  +	if ((m >= lowerBounds) && (m < upperBounds)) {
  +	    final String result = Double.toString(d);
  +	    final int length = result.length();
  +	    // Remove leading zeros.
  +	    if ((result.charAt(length-2) == '.') &&
  +		(result.charAt(length-1) == '0'))
  +		return result.substring(0, length-2);
  +	    else
  +		return result;
   	}
  -	return result;
  +	else {
  +	    return formatNumber(d, defaultPattern, defaultFormatter);
  +	}
       }
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org