📄 decimalformat.java
字号:
if (subparse(text, pos, exponentDigits, true, stat) && exponentDigits.fitsIntoLong(stat[STATUS_POSITIVE], true)) { position = pos.index; // Advance past the exponent exponent = (int)exponentDigits.getLong(); if (!stat[STATUS_POSITIVE]) exponent = -exponent; sawExponent = true; } break; // Whether we fail or succeed, we exit this loop } else break; } if (backup != -1) position = backup; // If there was no decimal point we have an integer if (!sawDecimal) digits.decimalAt = digitCount; // Not digits.count! // Adjust for exponent, if any digits.decimalAt += exponent; // If none of the text string was recognized. For example, parse // "x" with pattern "#0.00" (return index and error index both 0) // parse "$" with pattern "$#0.00". (return index 0 and error index // 1). if (!sawDigit && digitCount == 0) { parsePosition.index = oldStart; parsePosition.errorIndex = oldStart; return false; } } // check for positiveSuffix if (gotPositive) gotPositive = text.regionMatches(position,positiveSuffix,0, positiveSuffix.length()); if (gotNegative) gotNegative = text.regionMatches(position,negativeSuffix,0, negativeSuffix.length()); // if both match, take longest if (gotPositive && gotNegative) { if (positiveSuffix.length() > negativeSuffix.length()) gotNegative = false; else if (positiveSuffix.length() < negativeSuffix.length()) gotPositive = false; } // fail if neither or both if (gotPositive == gotNegative) { parsePosition.errorIndex = position; return false; } parsePosition.index = position + (gotPositive ? positiveSuffix.length() : negativeSuffix.length()); // mark success! status[STATUS_POSITIVE] = gotPositive; if (parsePosition.index == oldStart) { parsePosition.errorIndex = position; return false; } return true; } /** * Returns the decimal format symbols, which is generally not changed * by the programmer or user. * @return desired DecimalFormatSymbols * @see java.text.DecimalFormatSymbols */ public DecimalFormatSymbols getDecimalFormatSymbols() { try { // don't allow multiple references return (DecimalFormatSymbols) symbols.clone(); } catch (Exception foo) { return null; // should never happen } } /** * Sets the decimal format symbols, which is generally not changed * by the programmer or user. * @param newSymbols desired DecimalFormatSymbols * @see java.text.DecimalFormatSymbols */ public void setDecimalFormatSymbols(DecimalFormatSymbols newSymbols) { try { // don't allow multiple references symbols = (DecimalFormatSymbols) newSymbols.clone(); expandAffixes(); } catch (Exception foo) { // should never happen } } /** * Get the positive prefix. * <P>Examples: +123, $123, sFr123 */ public String getPositivePrefix () { return positivePrefix; } /** * Set the positive prefix. * <P>Examples: +123, $123, sFr123 */ public void setPositivePrefix (String newValue) { positivePrefix = newValue; posPrefixPattern = null; positivePrefixFieldPositions = null; } /** * Returns the FieldPositions of the fields in the prefix used for * positive numbers. This is not used if the user has explicitly set * a positive prefix via <code>setPositivePrefix</code>. This is * lazily created. * * @return FieldPositions in positive prefix */ private FieldPosition[] getPositivePrefixFieldPositions() { if (positivePrefixFieldPositions == null) { if (posPrefixPattern != null) { positivePrefixFieldPositions = expandAffix(posPrefixPattern); } else { positivePrefixFieldPositions = EmptyFieldPositionArray; } } return positivePrefixFieldPositions; } /** * Get the negative prefix. * <P>Examples: -123, ($123) (with negative suffix), sFr-123 */ public String getNegativePrefix () { return negativePrefix; } /** * Set the negative prefix. * <P>Examples: -123, ($123) (with negative suffix), sFr-123 */ public void setNegativePrefix (String newValue) { negativePrefix = newValue; negPrefixPattern = null; } /** * Returns the FieldPositions of the fields in the prefix used for * negative numbers. This is not used if the user has explicitly set * a negative prefix via <code>setNegativePrefix</code>. This is * lazily created. * * @return FieldPositions in positive prefix */ private FieldPosition[] getNegativePrefixFieldPositions() { if (negativePrefixFieldPositions == null) { if (negPrefixPattern != null) { negativePrefixFieldPositions = expandAffix(negPrefixPattern); } else { negativePrefixFieldPositions = EmptyFieldPositionArray; } } return negativePrefixFieldPositions; } /** * Get the positive suffix. * <P>Example: 123% */ public String getPositiveSuffix () { return positiveSuffix; } /** * Set the positive suffix. * <P>Example: 123% */ public void setPositiveSuffix (String newValue) { positiveSuffix = newValue; posSuffixPattern = null; } /** * Returns the FieldPositions of the fields in the suffix used for * positive numbers. This is not used if the user has explicitly set * a positive suffix via <code>setPositiveSuffix</code>. This is * lazily created. * * @return FieldPositions in positive prefix */ private FieldPosition[] getPositiveSuffixFieldPositions() { if (positiveSuffixFieldPositions == null) { if (posSuffixPattern != null) { positiveSuffixFieldPositions = expandAffix(posSuffixPattern); } else { positiveSuffixFieldPositions = EmptyFieldPositionArray; } } return positiveSuffixFieldPositions; } /** * Get the negative suffix. * <P>Examples: -123%, ($123) (with positive suffixes) */ public String getNegativeSuffix () { return negativeSuffix; } /** * Set the positive suffix. * <P>Examples: 123% */ public void setNegativeSuffix (String newValue) { negativeSuffix = newValue; negSuffixPattern = null; } /** * Returns the FieldPositions of the fields in the suffix used for * negative numbers. This is not used if the user has explicitly set * a negative suffix via <code>setNegativeSuffix</code>. This is * lazily created. * * @return FieldPositions in positive prefix */ private FieldPosition[] getNegativeSuffixFieldPositions() { if (negativeSuffixFieldPositions == null) { if (negSuffixPattern != null) { negativeSuffixFieldPositions = expandAffix(negSuffixPattern); } else { negativeSuffixFieldPositions = EmptyFieldPositionArray; } } return negativeSuffixFieldPositions; } /** * Get the multiplier for use in percent, permill, etc. * For a percentage, set the suffixes to have "%" and the multiplier to be 100. * (For Arabic, use arabic percent symbol). * For a permill, set the suffixes to have "\u2031" and the multiplier to be 1000. * <P>Examples: with 100, 1.23 -> "123", and "123" -> 1.23 */ public int getMultiplier () { return multiplier; } /** * Set the multiplier for use in percent, permill, etc. * For a percentage, set the suffixes to have "%" and the multiplier to be 100. * (For Arabic, use arabic percent symbol). * For a permill, set the suffixes to have "\u2031" and the multiplier to be 1000. * <P>Examples: with 100, 1.23 -> "123", and "123" -> 1.23 */ public void setMultiplier (int newValue) { multiplier = newValue; } /** * Return the grouping size. Grouping size is the number of digits between * grouping separators in the integer portion of a number. For example, * in the number "123,456.78", the grouping size is 3. * @see #setGroupingSize * @see java.text.NumberFormat#isGroupingUsed * @see java.text.DecimalFormatSymbols#getGroupingSeparator */ public int getGroupingSize () { return groupingSize; } /** * Set the grouping size. Grouping size is the number of digits between * grouping separators in the integer portion of a number. For example, * in the number "123,456.78", the grouping size is 3. * @see #getGroupingSize * @see java.text.NumberFormat#setGroupingUsed * @see java.text.DecimalFormatSymbols#setGroupingSeparator */ public void setGroupingSize (int newValue) { groupingSize = (byte)newValue; } /** * Allows you to get the behavior of the decimal separator with integers. * (The decimal separator will always appear with decimals.) * <P>Example: Decimal ON: 12345 -> 12345.; OFF: 12345 -> 12345 */ public boolean isDecimalSeparatorAlwaysShown() { return decimalSeparatorAlwaysShown; } /** * Allows you to set the behavior of the decimal separator with integers. * (The decimal separator will always appear with decimals.) * <P>Example: Decimal ON: 12345 -> 12345.; OFF: 12345 -> 12345 */ public void setDecimalSeparatorAlwaysShown(boolean newValue) { decimalSeparatorAlwaysShown = newValue; } /** * Standard override; no change
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -