public String toFormulaString() { return NumberToTextConverter.toText(field_1_value); } }
private static void formatLessThanOne(StringBuilder sb, String decimalDigits, int decExponent, int countSigDigits) { int nLeadingZeros = -decExponent - 1; int normalLength = 2 + nLeadingZeros + countSigDigits; // 2 == "0.".length() if (needsScientificNotation(normalLength)) { sb.append(decimalDigits.charAt(0)); if (countSigDigits > 1) { sb.append('.'); sb.append(decimalDigits.subSequence(1, countSigDigits)); } sb.append("E-"); appendExp(sb, -decExponent); return; } sb.append("0."); for (int i=nLeadingZeros; i>0; i--) { sb.append('0'); } sb.append(decimalDigits.subSequence(0, countSigDigits)); }
sb.append('-'); convertToText(sb, nd); return sb.toString();
private static void convertToText(StringBuilder sb, NormalisedDecimal pnd) { NormalisedDecimal rnd = pnd.roundUnits(); int decExponent = rnd.getDecimalExponent(); String decimalDigits; if (Math.abs(decExponent)>98) { decimalDigits = rnd.getSignificantDecimalDigitsLastDigitRounded(); if (decimalDigits.length() == 16) { // rounding caused carry decExponent++; } } else { decimalDigits = rnd.getSignificantDecimalDigits(); } int countSigDigits = countSignifantDigits(decimalDigits); if (decExponent < 0) { formatLessThanOne(sb, decimalDigits, decExponent, countSigDigits); } else { formatGreaterThanOne(sb, decimalDigits, decExponent, countSigDigits); } }
/** * Converts the supplied <tt>value</tt> to the text representation that Excel would give if * the value were to appear in an unformatted cell, or as a literal number in a formula.<br> * Note - the results from this method differ slightly from those of <tt>Double.toString()</tt> * In some special cases Excel behaves quite differently. This function attempts to reproduce * those results. */ public static String toText(double value) { return rawDoubleBitsToText(Double.doubleToLongBits(value)); } /* package */ static String rawDoubleBitsToText(long pRawBits) {
private static void formatGreaterThanOne(StringBuilder sb, String decimalDigits, int decExponent, int countSigDigits) { if (decExponent > 19) { // scientific notation sb.append(decimalDigits.charAt(0)); if (countSigDigits>1) { sb.append('.'); sb.append(decimalDigits.subSequence(1, countSigDigits)); } sb.append("E+"); appendExp(sb, decExponent); return; } int nFractionalDigits = countSigDigits - decExponent-1; if (nFractionalDigits > 0) { sb.append(decimalDigits.subSequence(0, decExponent+1)); sb.append('.'); sb.append(decimalDigits.subSequence(decExponent+1, countSigDigits)); return; } sb.append(decimalDigits.subSequence(0, countSigDigits)); for (int i=-nFractionalDigits; i>0; i--) { sb.append('0'); } }
private static void convertToText(StringBuilder sb, NormalisedDecimal pnd) { NormalisedDecimal rnd = pnd.roundUnits(); int decExponent = rnd.getDecimalExponent(); String decimalDigits; if (Math.abs(decExponent)>98) { decimalDigits = rnd.getSignificantDecimalDigitsLastDigitRounded(); if (decimalDigits.length() == 16) { // rounding caused carry decExponent++; } } else { decimalDigits = rnd.getSignificantDecimalDigits(); } int countSigDigits = countSignifantDigits(decimalDigits); if (decExponent < 0) { formatLessThanOne(sb, decimalDigits, decExponent, countSigDigits); } else { formatGreaterThanOne(sb, decimalDigits, decExponent, countSigDigits); } }
/** * Converts the supplied <tt>value</tt> to the text representation that Excel would give if * the value were to appear in an unformatted cell, or as a literal number in a formula.<br> * Note - the results from this method differ slightly from those of <tt>Double.toString()</tt> * In some special cases Excel behaves quite differently. This function attempts to reproduce * those results. */ public static String toText(double value) { return rawDoubleBitsToText(Double.doubleToLongBits(value)); } /* package */ static String rawDoubleBitsToText(long pRawBits) {
private static void formatGreaterThanOne(StringBuilder sb, String decimalDigits, int decExponent, int countSigDigits) { if (decExponent > 19) { // scientific notation sb.append(decimalDigits.charAt(0)); if (countSigDigits>1) { sb.append('.'); sb.append(decimalDigits.subSequence(1, countSigDigits)); } sb.append("E+"); appendExp(sb, decExponent); return; } int nFractionalDigits = countSigDigits - decExponent-1; if (nFractionalDigits > 0) { sb.append(decimalDigits.subSequence(0, decExponent+1)); sb.append('.'); sb.append(decimalDigits.subSequence(decExponent+1, countSigDigits)); return; } sb.append(decimalDigits.subSequence(0, countSigDigits)); for (int i=-nFractionalDigits; i>0; i--) { sb.append('0'); } }
public String getStringValue() { if (_stringValue == null) { _stringValue = NumberToTextConverter.toText(_value); } return _stringValue; } public final String toString() {
private static void convertToText(StringBuilder sb, NormalisedDecimal pnd) { NormalisedDecimal rnd = pnd.roundUnits(); int decExponent = rnd.getDecimalExponent(); String decimalDigits; if (Math.abs(decExponent)>98) { decimalDigits = rnd.getSignificantDecimalDigitsLastDigitRounded(); if (decimalDigits.length() == 16) { // rounding caused carry decExponent++; } } else { decimalDigits = rnd.getSignificantDecimalDigits(); } int countSigDigits = countSignifantDigits(decimalDigits); if (decExponent < 0) { formatLessThanOne(sb, decimalDigits, decExponent, countSigDigits); } else { formatGreaterThanOne(sb, decimalDigits, decExponent, countSigDigits); } }
private static void formatLessThanOne(StringBuilder sb, String decimalDigits, int decExponent, int countSigDigits) { int nLeadingZeros = -decExponent - 1; int normalLength = 2 + nLeadingZeros + countSigDigits; // 2 == "0.".length() if (needsScientificNotation(normalLength)) { sb.append(decimalDigits.charAt(0)); if (countSigDigits > 1) { sb.append('.'); sb.append(decimalDigits.subSequence(1, countSigDigits)); } sb.append("E-"); appendExp(sb, -decExponent); return; } sb.append("0."); for (int i=nLeadingZeros; i>0; i--) { sb.append('0'); } sb.append(decimalDigits.subSequence(0, countSigDigits)); }
/** * Converts the supplied <tt>value</tt> to the text representation that Excel would give if * the value were to appear in an unformatted cell, or as a literal number in a formula.<br/> * Note - the results from this method differ slightly from those of <tt>Double.toString()</tt> * In some special cases Excel behaves quite differently. This function attempts to reproduce * those results. */ public static String toText(double value) { return rawDoubleBitsToText(Double.doubleToLongBits(value)); } /* package */ static String rawDoubleBitsToText(long pRawBits) {
private static void formatGreaterThanOne(StringBuilder sb, String decimalDigits, int decExponent, int countSigDigits) { if (decExponent > 19) { // scientific notation sb.append(decimalDigits.charAt(0)); if (countSigDigits>1) { sb.append('.'); sb.append(decimalDigits.subSequence(1, countSigDigits)); } sb.append("E+"); appendExp(sb, decExponent); return; } int nFractionalDigits = countSigDigits - decExponent-1; if (nFractionalDigits > 0) { sb.append(decimalDigits.subSequence(0, decExponent+1)); sb.append('.'); sb.append(decimalDigits.subSequence(decExponent+1, countSigDigits)); return; } sb.append(decimalDigits.subSequence(0, countSigDigits)); for (int i=-nFractionalDigits; i>0; i--) { sb.append('0'); } }
sb.append('-'); convertToText(sb, nd); return sb.toString();
@Override protected void appendValueText(StringBuilder sb) { sb.append(" .value= ").append(NumberToTextConverter.toText(field_4_value)); }
private static void convertToText(StringBuilder sb, NormalisedDecimal pnd) { NormalisedDecimal rnd = pnd.roundUnits(); int decExponent = rnd.getDecimalExponent(); String decimalDigits; if (Math.abs(decExponent)>98) { decimalDigits = rnd.getSignificantDecimalDigitsLastDigitRounded(); if (decimalDigits.length() == 16) { // rounding caused carry decExponent++; } } else { decimalDigits = rnd.getSignificantDecimalDigits(); } int countSigDigits = countSignifantDigits(decimalDigits); if (decExponent < 0) { formatLessThanOne(sb, decimalDigits, decExponent, countSigDigits); } else { formatGreaterThanOne(sb, decimalDigits, decExponent, countSigDigits); } }
private static void formatLessThanOne(StringBuilder sb, String decimalDigits, int decExponent, int countSigDigits) { int nLeadingZeros = -decExponent - 1; int normalLength = 2 + nLeadingZeros + countSigDigits; // 2 == "0.".length() if (needsScientificNotation(normalLength)) { sb.append(decimalDigits.charAt(0)); if (countSigDigits > 1) { sb.append('.'); sb.append(decimalDigits.subSequence(1, countSigDigits)); } sb.append("E-"); appendExp(sb, -decExponent); return; } sb.append("0."); for (int i=nLeadingZeros; i>0; i--) { sb.append('0'); } sb.append(decimalDigits.subSequence(0, countSigDigits)); }
/** * Converts the supplied <tt>value</tt> to the text representation that Excel would give if * the value were to appear in an unformatted cell, or as a literal number in a formula.<br/> * Note - the results from this method differ slightly from those of <tt>Double.toString()</tt> * In some special cases Excel behaves quite differently. This function attempts to reproduce * those results. */ public static String toText(double value) { return rawDoubleBitsToText(Double.doubleToLongBits(value)); } /* package */ static String rawDoubleBitsToText(long pRawBits) {
private static void formatGreaterThanOne(StringBuilder sb, String decimalDigits, int decExponent, int countSigDigits) { if (decExponent > 19) { // scientific notation sb.append(decimalDigits.charAt(0)); if (countSigDigits>1) { sb.append('.'); sb.append(decimalDigits.subSequence(1, countSigDigits)); } sb.append("E+"); appendExp(sb, decExponent); return; } int nFractionalDigits = countSigDigits - decExponent-1; if (nFractionalDigits > 0) { sb.append(decimalDigits.subSequence(0, decExponent+1)); sb.append('.'); sb.append(decimalDigits.subSequence(decExponent+1, countSigDigits)); return; } sb.append(decimalDigits.subSequence(0, countSigDigits)); for (int i=-nFractionalDigits; i>0; i--) { sb.append('0'); } }