jaxp/src/com/sun/org/apache/xalan/internal/xsltc/runtime/BasisLibrary.java

Print this page




 938      * Removes the decimal if null. Uses a specialized formatter object
 939      * for very large and very small numbers that ignores locales, thus
 940      * using always using "." as a decimal separator.
 941      */
 942     public static String realToString(double d) {
 943         final double m = Math.abs(d);
 944         if ((m >= lowerBounds) && (m < upperBounds)) {
 945             final String result = Double.toString(d);
 946             final int length = result.length();
 947             // Remove leading zeros.
 948             if ((result.charAt(length-2) == '.') &&
 949                 (result.charAt(length-1) == '0'))
 950                 return result.substring(0, length-2);
 951             else
 952                 return result;
 953         }
 954         else {
 955             if (Double.isNaN(d) || Double.isInfinite(d))
 956                 return(Double.toString(d));
 957 



 958             // Use the XPath formatter to ignore locales
 959             StringBuffer result = threadLocalStringBuffer.get();
 960             result.setLength(0);
 961             xpathFormatter.format(d, result, _fieldPosition);
 962             return result.toString();
 963         }
 964     }
 965 
 966     /**
 967      * Utility function: used in RealType to convert a real to an integer
 968      */
 969     public static int realToInt(double d) {
 970         return (int)d;
 971     }
 972 
 973     /**
 974      * Utility function: used to format/adjust  a double to a string. The
 975      * DecimalFormat object comes from the 'formatSymbols' hashtable in
 976      * AbstractTranslet.
 977      */




 938      * Removes the decimal if null. Uses a specialized formatter object
 939      * for very large and very small numbers that ignores locales, thus
 940      * using always using "." as a decimal separator.
 941      */
 942     public static String realToString(double d) {
 943         final double m = Math.abs(d);
 944         if ((m >= lowerBounds) && (m < upperBounds)) {
 945             final String result = Double.toString(d);
 946             final int length = result.length();
 947             // Remove leading zeros.
 948             if ((result.charAt(length-2) == '.') &&
 949                 (result.charAt(length-1) == '0'))
 950                 return result.substring(0, length-2);
 951             else
 952                 return result;
 953         }
 954         else {
 955             if (Double.isNaN(d) || Double.isInfinite(d))
 956                 return(Double.toString(d));
 957 
 958             //Convert -0.0 to +0.0 other values remains the same
 959             d = d + 0.0;
 960 
 961             // Use the XPath formatter to ignore locales
 962             StringBuffer result = threadLocalStringBuffer.get();
 963             result.setLength(0);
 964             xpathFormatter.format(d, result, _fieldPosition);
 965             return result.toString();
 966         }
 967     }
 968 
 969     /**
 970      * Utility function: used in RealType to convert a real to an integer
 971      */
 972     public static int realToInt(double d) {
 973         return (int)d;
 974     }
 975 
 976     /**
 977      * Utility function: used to format/adjust  a double to a string. The
 978      * DecimalFormat object comes from the 'formatSymbols' hashtable in
 979      * AbstractTranslet.
 980      */