Example #1
0
        /**
         * <p>Turns {@link BigDecimal} to a string representation.</p>
         *
         * <p>Due to a behavior change in the {@link BigDecimal#toString()}
         * method in JDK1.5, this had to be implemented here.</p>
         *
         * @param bd <code>BigDecimal</code> to format as a <code>String</code>
         *
         * @return  <code>String</code> representation of <code>BigDecimal</code>
         */
        private String toString(java.math.BigDecimal bd)
        {
            String intString = bd.unscaledValue().toString();
            int scale = bd.scale();

            if (scale == 0)
            {
                return intString;
            }

            /* Insert decimal point */
            java.lang.StringBuffer buf;
            int insertionPoint = intString.length() - scale;
            if (insertionPoint == 0)
            { /* Point goes right before intVal */
                return "0." + intString;
            }
            else if (insertionPoint > 0)
            { /* Point goes inside intVal */
                buf = new java.lang.StringBuffer(intString);
                buf.insert(insertionPoint, '.');
            }
            else
            { /* We must insert zeros between point and intVal */
                buf = new java.lang.StringBuffer(3 - insertionPoint + intString.length());
                buf.append("0.");
                for (int i = 0; i < -insertionPoint; i++)
                {
                    buf.append('0');
                }
                buf.append(intString);
            }
            return buf.toString();
        }