阿拉伯数字转换成中文,小数点后四舍五入保留两位. 使用于整数、小数的转换.

@param amount 数字
@param isUseTraditional 是否使用繁体
@param isMoneyMode 是否为金额模式
@return 中文
504821
public static String format(double amount, boolean isUseTraditional, boolean isMoneyMode) {
		final String[] numArray = isUseTraditional ? traditionalDigits : simpleDigits;

		if (amount > 99999999999999.99 || amount < -99999999999999.99) {
			throw new IllegalArgumentException("Number support only: (-99999999999999.99 ～ 99999999999999.99)！");
		}

		boolean negative = false;
		if (amount < 0) {
			negative = true;
			amount = - amount;
		}

		long temp = Math.round(amount * 100);
		int numFen = (int) (temp % 10);
		temp = temp / 10;
		int numJiao = (int) (temp % 10);
		temp = temp / 10;

		//将数字以万为单位分为多份
		int[] parts = new int[20];
		int numParts = 0;
		for (int i = 0; temp != 0; i++) {
			int part = (int) (temp % 10000);
			parts[i] = part;
			numParts++;
			temp = temp / 10000;
		}

		boolean beforeWanIsZero = true; // 标志“万”下面一级是不是 0

		String chineseStr = StrUtil.EMPTY;
		for (int i = 0; i < numParts; i++) {
			String partChinese = toChinese(parts[i], isUseTraditional);
			if (i % 2 == 0) {
				beforeWanIsZero = StrUtil.isEmpty(partChinese);
			}

			if (i != 0) {
				if (i % 2 == 0) {
					chineseStr = "亿" + chineseStr;
				} else {
					if ("".equals(partChinese) && false == beforeWanIsZero) {
						// 如果“万”对应的 part 为 0，而“万”下面一级不为 0，则不加“万”，而加“零”
						chineseStr = "零" + chineseStr;
					} else {
						if (parts[i - 1] < 1000 && parts[i - 1] > 0) {
							// 如果"万"的部分不为 0, 而"万"前面的部分小于 1000 大于 0， 则万后面应该跟“零”
							chineseStr = "零" + chineseStr;
						}
						chineseStr = "万" + chineseStr;
					}
				}
			}
			chineseStr = partChinese + chineseStr;
		}

		// 整数部分为 0, 则表达为"零"
		if (StrUtil.EMPTY.equals(chineseStr)) {
			chineseStr = numArray[0];
		}
		//负数
		if (negative) { // 整数部分不为 0
			chineseStr = "负" + chineseStr;
		}

		// 小数部分
		if (numFen != 0 || numJiao != 0) {
			if (numFen == 0) {
				chineseStr += (isMoneyMode ? "元" : "点") + numArray[numJiao] + (isMoneyMode ? "角" : "");
			} else { // “分”数不为 0
				if (numJiao == 0) {
					chineseStr += (isMoneyMode ? "元零" : "点零") + numArray[numFen] + (isMoneyMode ? "分" : "");
				} else {
					chineseStr += (isMoneyMode ? "元" : "点") + numArray[numJiao] + (isMoneyMode ? "角" : "") + numArray[numFen] + (isMoneyMode ? "分" : "");
				}
			}
		}else if(isMoneyMode) {
			//无小数部分的金额结尾
			chineseStr += "元整";
		}

		return chineseStr;

	}
642410
public double getAndSet(double amount) {
    long v = value.getAndSet(Double.doubleToLongBits(amount));
    return Double.longBitsToDouble(v);
  }
484532
@Override
    public MatchStrength hasFormat(InputAccessor acc) throws IOException
    {
        if (!acc.hasMoreBytes()) {
            return MatchStrength.INCONCLUSIVE;
        }
        byte b = acc.nextByte();
        // Very first thing, a UTF-8 BOM?
        if (b == UTF8_BOM_1) { // yes, looks like UTF-8 BOM
            if (!acc.hasMoreBytes()) {
                return MatchStrength.INCONCLUSIVE;
            }
            if (acc.nextByte() != UTF8_BOM_2) {
                return MatchStrength.NO_MATCH;
            }
            if (!acc.hasMoreBytes()) {
                return MatchStrength.INCONCLUSIVE;
            }
            if (acc.nextByte() != UTF8_BOM_3) {
                return MatchStrength.NO_MATCH;
            }
            if (!acc.hasMoreBytes()) {
                return MatchStrength.INCONCLUSIVE;
            }
            b = acc.nextByte();
        }
        if (b == '{' || Character.isLetter((char) b) || Character.isDigit((char) b)) {
            return MatchStrength.WEAK_MATCH;
        }
        return MatchStrength.INCONCLUSIVE;
    }
1348658
public static function moneyFormat($amount, $options = []) {
		$format = array_merge_hard(self::$options['locale_options'], $options['locale_options'] ?? []);
		$options['decimals'] = $options['decimals'] ?? 2;
		// sometimes symbols contain decimal point, we change it to thousands_sep
		if (!empty($options['symbol'])) {
			$options['symbol'] = str_replace($format['mon_decimal_point'], $format['mon_thousands_sep'], $options['symbol']);
		} else {
			$options['symbol'] = '';
		}
		// convert to string
		if (!is_string($amount)) {
			$amount = $amount . '';
		}
		$negative = strpos($amount, '-') !== false;
		$amount = ltrim($amount, '-');
		// if the number portion has been formatted
		if (empty($options['amount_partially_formatted'])) {
			$temp = explode('.', $amount);
			$number = $temp[0];
			$fraction = $temp[1] ?? '';
			// process number
			if (empty($number)) $number = '0';
			if ($format['mon_thousands_sep'] . '' !== '' && !empty($format['mon_grouping'])) {
				$counter = 0;
				$mon_grouping = [];
				$symbols = array_reverse(mb_str_split($number), true);
				$number = '';
				foreach ($symbols as $k => $v) {
					// grab group size
					if ($counter == 0) {
						if (empty($mon_grouping)) $mon_grouping = $format['mon_grouping'];
						if (count($mon_grouping) > 1) {
							$counter = array_shift($mon_grouping);
						} else {
							$counter = $mon_grouping[0];
						}
					}
					// skip number of characters
					$counter--;
					$number = $v . $number;
					if ($counter == 0 && $k > 0) {
						$number = $format['mon_thousands_sep'] . $number;
					}
				}
			}
			// left precision
			if (!empty($options['digits'])) {
				if (strlen($number) < $options['digits']) {
					$number = str_pad($number, $options['digits'], ' ', STR_PAD_LEFT);
				}
			}
			// right precision
			if ($options['decimals'] > 0) {
				$fraction = substr(str_pad($fraction, $options['decimals'], '0', STR_PAD_RIGHT), 0, $options['decimals']);
				$number = $number . $format['mon_decimal_point'] . $fraction;
			}
		} else {
			$number = $amount;
		}
		// translate characters
		$number = self::numberToFromNativeLanguage($number, $options);
		// format based on settings
		$cs_precedes = $negative ? $format['n_cs_precedes'] : $format['p_cs_precedes'];
		$sep_by_space = $negative ? $format['n_sep_by_space'] : $format['p_sep_by_space'];
		$sign_posn = $negative ? $format['n_sign_posn'] : $format['p_sign_posn'];
		// if accounting formatting
		if (!empty($options['accounting'])) {
			// if we have currency symbol we added it based on settings
			if (!empty($options['symbol'])) {
				$number = ($cs_precedes ? ($options['symbol'] . ($sep_by_space === 1 ? ' ' : '')) : '') . $number . (!$cs_precedes ? (($sep_by_space === 1 ? ' ' : '') . $options['symbol']) : '');
			}
			if ($negative) {
				$number = '(' . $number . ')';
			} else {
				$number = ' ' . $number . ' ';
			}
		} else {
			$positive_sign = $format['positive_sign'];
			$negative_sign = $format['negative_sign'];
			$sign = $negative ? $negative_sign : $positive_sign;
			$other_sign = $negative ? $positive_sign : $negative_sign;
			$sign_padding = '';
			if ($sign_posn) {
				for ($i = 0; $i < (strlen($other_sign) - strlen($sign)); $i++) {
					$sign_padding.= ' ';
				}
			}
			$temp_value = '';
			switch ($sign_posn) {
				case 0: // parentheses surround value and currency symbol
					if (!empty($options['symbol'])) {
						$number = $cs_precedes ? ($options['symbol'] . ($sep_by_space === 1 ? ' ' : '') . $number) : ($number . ($sep_by_space === 1 ? ' ' : '') . $options['symbol']);
					}
					$number = '(' . $number . ')';
					break;
				case 1: // sign precedes
					if (!empty($options['symbol'])) {
						$number = $cs_precedes ? ($options['symbol'] . ($sep_by_space === 1 ? ' ' : '') . $number) : ($number . ($sep_by_space === 1 ? ' ' : '') . $options['symbol']);
					}
					$number = $sign_padding . $sign . ($sep_by_space === 2 ? ' ' : '') . $number;
					break;
				case 2: // sign follows
					if (!empty($options['symbol'])) {
						$number = $cs_precedes ? ($options['symbol'] . ($sep_by_space === 1 ? ' ' : '') . $number) : ($number . ($sep_by_space === 1 ? ' ' : '') . $options['symbol']);
					}
					$number = $number . ($sep_by_space === 2 ? ' ' : '') . $sign . $sign_padding;
					break;
				case 3: //sign precedes currency symbol
					$symbol = '';
					if (!empty($options['symbol'])) {
						$symbol = $cs_precedes ? ($options['symbol'] . ($sep_by_space === 1 ? ' ' : '')) : (($sep_by_space === 2 ? ' ' : '') . $options['symbol']);
					}
					$number = $cs_precedes ? ($sign_padding . $sign . ($sep_by_space === 2 ? ' ' : '') . $symbol . $number) : ($number . ($sep_by_space === 1 ? ' ' : '') . $sign . $sign_padding . $symbol);
					break;
				case 4: // sign succeeds currency symbol
					$symbol = '';
					$symbol_sep = '';
					if (!empty($options['symbol'])) {
						$symbol = $options['symbol'];
						$symbol_sep = ($sep_by_space === 1 ? ' ' : '');
					}
					$number = $cs_precedes ? ($symbol . ($sep_by_space === 2 ? ' ' : '') . $sign_padding . $sign . $symbol_sep . $number) : ($number . $symbol_sep . $symbol . ($sep_by_space === 2 ? ' ' : '') . $sign . $sign_padding);
					break;
			}
		}
		return $number;
	}
1177747
@SuppressWarnings("unchecked")
    protected Optional<NumberFormatWrapper<N>> createFormatter(final FieldAccessor field, final Configuration config) {
        
        final Optional<CsvNumberFormat> formatAnno = field.getAnnotation(CsvNumberFormat.class);
        
        if(!formatAnno.isPresent()) {
            return Optional.empty();
        }
        
        final String pattern = formatAnno.get().pattern();
        if(pattern.isEmpty()) {
            return Optional.empty();
        }
        
        final boolean lenient = formatAnno.get().lenient();
        final Locale locale = Utils.getLocale(formatAnno.get().locale());
        final Optional<Currency> currency = formatAnno.get().currency().isEmpty() ? Optional.empty()
                : Optional.of(Currency.getInstance(formatAnno.get().currency()));
        final RoundingMode roundingMode = formatAnno.get().rounding();
        final DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale);
        
        final DecimalFormat formatter = new DecimalFormat(pattern, symbols);
        formatter.setParseBigDecimal(true);
        formatter.setRoundingMode(roundingMode);
        currency.ifPresent(c -> formatter.setCurrency(c));
        
        final NumberFormatWrapper<N> wrapper = new NumberFormatWrapper<>(formatter, (Class<N>)field.getType(), lenient);
        wrapper.setValidationMessage(formatAnno.get().message());
        
        return Optional.of(wrapper);
        
    }
1178827
function hincrbyfloat(key, field, amount, req) {
  var map = this.getKey(key, req)
    , val;
  if(!map) {
    map = new HashMap();
    this.setKey(key, map, undefined, undefined, undefined, req);
  }
  val = utils.strtofloat(map.getKey(field));
  amount = utils.strtofloat(amount);
  val += amount;
  map.setKey(field, val);
  // store as number and return a number,
  // the command implementation should coerce the result
  // to a string for a bulk string reply
  return val;
}
661633
public static function formatAsMoney($value, $currencySymbol = "&pound;", $roundToInteger = false) {
        if (is_numeric($value))
            return $currencySymbol . number_format($value, $roundToInteger ? 0 : 2, ".", "");
        else
            return null;
    }
997655
private boolean isToken(String value) {
        int len = value.length();
        for (int i = 0; i < len; i++) {
            char c = value.charAt(i);
            if (c < 0x20 || c >= 0x7f || TSPECIALS.indexOf(c) != -1) {
                return false;
            }
        }

        return true;
    }
333447
public StringBuffer format(CurrencyAmount currAmt,
                               StringBuffer toAppendTo,
                               FieldPosition pos) {
        // Default implementation -- subclasses may override
        synchronized(this) {
            Currency save = getCurrency(), curr = currAmt.getCurrency();
            boolean same = curr.equals(save);
            if (!same) setCurrency(curr);
            format(currAmt.getNumber(), toAppendTo, pos);
            if (!same) setCurrency(save);
        }
        return toAppendTo;
    }
381869
public static boolean isAllNum(String str)
    {
        if (str == null)
            return false;

        int i = 0;
        /** 判断开头是否是+-之类的符号 */
        if ("±+-＋－—".indexOf(str.charAt(0)) != -1)
            i++;
        /** 如果是全角的０１２３４５６７８９ 字符* */
        while (i < str.length() && "０１２３４５６７８９".indexOf(str.charAt(i)) != -1)
            i++;
        // Get middle delimiter such as .
        if (i > 0 && i < str.length())
        {
            char ch = str.charAt(i);
            if ("·∶:，,．.／/".indexOf(ch) != -1)
            {// 98．1％
                i++;
                while (i < str.length() && "０１２３４５６７８９".indexOf(str.charAt(i)) != -1)
                    i++;
            }
        }
        if (i >= str.length())
            return true;

        /** 如果是半角的0123456789字符* */
        while (i < str.length() && "0123456789".indexOf(str.charAt(i)) != -1)
            i++;
        // Get middle delimiter such as .
        if (i > 0 && i < str.length())
        {
            char ch = str.charAt(i);
            if (',' == ch || '.' == ch || '/' == ch  || ':' == ch || "∶·，．／".indexOf(ch) != -1)
            {// 98．1％
                i++;
                while (i < str.length() && "0123456789".indexOf(str.charAt(i)) != -1)
                    i++;
            }
        }

        if (i < str.length())
        {
            if ("百千万亿佰仟%％‰".indexOf(str.charAt(i)) != -1)
                i++;
        }
        if (i >= str.length())
            return true;

        return false;
    }
601310
public boolean isNumeral(final String input) {
        for (int i = 0; i < input.length(); i++) {
            if (!isNumeral(input.charAt(i))) {
                return false;
            }
        }
        return true;
    }
441347
public static boolean isValid(final String value) {
        if (value == null) {
            return true;
        }
        if (value.length() == 0) {
            return false;
        }
        final int space = value.indexOf(' ');
        if (space == -1) {
            return false;
        }

        // Try converting amount
        final String amount = value.substring(0, space);
        if (!(amount.matches(DECIMAL) || amount.matches(INTEGER))) {
            return false;
        }

        // Try to convert code into a currency
        final String currencyCode = value.substring(space + 1);
        try {
            Currency.getInstance(currencyCode);
        } catch (RuntimeException ex) {
            return false;
        }

        return true;
    }
990421
@Override
        public HebrewTime addTo(
            HebrewTime context,
            long amount
        ) {

            if (amount == 0) {
                return context;
            }

            int h;
            int p;

            switch (this.unit) {
                case HOURS:
                    h = MathUtils.floorModulo(MathUtils.safeAdd(context.hour23, amount), 24);
                    p = context.part;
                    break;
                case HALAKIM:
                    long sum = MathUtils.safeAdd(context.part, amount);
                    p = MathUtils.floorModulo(sum, PARTS_IN_HOUR);
                    long overflow = MathUtils.floorDivide(sum, PARTS_IN_HOUR);
                    h = MathUtils.floorModulo(MathUtils.safeAdd(context.hour23, overflow), 24);
                    break;
                default:
                    throw new UnsupportedOperationException(this.unit.name());
            }

            return new HebrewTime(h, p);

        }
1219324
public static function currencyFormat($format, $number, $useSimbol = false) {
        $regex = '/%((?:[\^!\-]|\+|\(|\=.)*)([0-9]+)?' .
                '(?:#([0-9]+))?(?:\.([0-9]+))?([in%])/';
        if (setlocale(LC_MONETARY, 0) == 'C') {
            setlocale(LC_MONETARY, '');
        }
        $locale = localeconv();
        preg_match_all($regex, $format, $matches, PREG_SET_ORDER);
        foreach ($matches as $fmatch) {
            $value = floatval($number);
            $flags = array(
                'fillchar' => preg_match('/\=(.)/', $fmatch[1], $match) ?
                        $match[1] : ' ',
                'nogroup' => preg_match('/\^/', $fmatch[1]) > 0,
                'usesignal' => preg_match('/\+|\(/', $fmatch[1], $match) ?
                        $match[0] : '+',
                'nosimbol' => preg_match('/\!/', $fmatch[1]) > 0,
                'isleft' => preg_match('/\-/', $fmatch[1]) > 0
            );
            $width = trim($fmatch[2]) ? (int) $fmatch[2] : 0;
            $left = trim($fmatch[3]) ? (int) $fmatch[3] : 0;
            $right = trim($fmatch[4]) ? (int) $fmatch[4] : $locale['int_frac_digits'];
            $conversion = $fmatch[5];

            $positive = true;
            if ($value < 0) {
                $positive = false;
                $value *= - 1;
            }
            $letter = $positive ? 'p' : 'n';

            $prefix = $suffix = $cprefix = $csuffix = $signal = '';

            $signal = $positive ? $locale['positive_sign'] : $locale['negative_sign'];
            switch (true) {
                case $locale["{$letter}_sign_posn"] == 1 && $flags['usesignal'] == '+':
                    $prefix = $signal;
                    break;
                case $locale["{$letter}_sign_posn"] == 2 && $flags['usesignal'] == '+':
                    $suffix = $signal;
                    break;
                case $locale["{$letter}_sign_posn"] == 3 && $flags['usesignal'] == '+':
                    $cprefix = $signal;
                    break;
                case $locale["{$letter}_sign_posn"] == 4 && $flags['usesignal'] == '+':
                    $csuffix = $signal;
                    break;
                case $flags['usesignal'] == '(':
                case $locale["{$letter}_sign_posn"] == 0:
                    $prefix = '(';
                    $suffix = ')';
                    break;
            }
            if (!$flags['nosimbol']) {
                $currency = $cprefix .
                        ($conversion == 'i' ? $locale['int_curr_symbol'] : $locale['currency_symbol']) .
                        $csuffix;
            } else {
                $currency = '';
            }
            $space = $locale["{$letter}_sep_by_space"] ? ' ' : '';

            $value = number_format($value, $right, $locale['mon_decimal_point'], $flags['nogroup'] ? '' : $locale['mon_thousands_sep']);
            $value = @explode($locale['mon_decimal_point'], $value);

            $n = strlen($prefix) + strlen($currency) + strlen($value[0]);
            if ($left > 0 && $left > $n) {
                $value[0] = str_repeat($flags['fillchar'], $left - $n) . $value[0];
            }
            $value = implode($locale['mon_decimal_point'], $value);

            if ($useSimbol) {

                if ($locale["{$letter}_cs_precedes"]) {
                    $value = $prefix . $currency . $space . $value . $suffix;
                } else {
                    $value = $prefix . $value . $space . $currency . $suffix;
                }
                if ($width > 0) {
                    $value = str_pad($value, $width, $flags['fillchar'], $flags['isleft'] ?
                                    STR_PAD_RIGHT : STR_PAD_LEFT);
                }
            }
            $format = str_replace($fmatch[0], $value, $format);
        }

        return $format;
    }
430042
private static boolean isToken(String value) {
        // ----- BEGIN android -----
        if (RESERVED_NAMES.contains(value.toLowerCase(Locale.US))) {
            return false;
        }
        // ----- END android -----

        int len = value.length();

        for (int i = 0; i < len; i++) {
            char c = value.charAt(i);

            if (c < 0x20 || c >= 0x7f || tspecials.indexOf(c) != -1)
                return false;
        }
        return true;
    }
75123
private String getFormattedAmountByLocaleAndInvoiceCurrency(final BigDecimal amount) {
        final String invoiceCurrencyCode = invoice.getCurrency().toString();
        final CurrencyUnit currencyUnit = CurrencyUnit.of(invoiceCurrencyCode);

        final DecimalFormat numberFormatter = (DecimalFormat) DecimalFormat.getCurrencyInstance(locale);
        final DecimalFormatSymbols dfs = numberFormatter.getDecimalFormatSymbols();
        dfs.setInternationalCurrencySymbol(currencyUnit.getCurrencyCode());

        try {
            Currency currency = Currency.fromCode(invoiceCurrencyCode);
            dfs.setCurrencySymbol(currency.getSymbol());
        } catch (final IllegalArgumentException e) {
            dfs.setCurrencySymbol(currencyUnit.getSymbol(locale));
        }

        numberFormatter.setDecimalFormatSymbols(dfs);
        numberFormatter.setMinimumFractionDigits(currencyUnit.getDefaultFractionDigits());
        numberFormatter.setMaximumFractionDigits(currencyUnit.getDefaultFractionDigits());

        return numberFormatter.format(amount.doubleValue());
    }
527013
protected String getToken(MonetaryAmount amount) {
        switch (style) {
            case NUMERIC_CODE:
                return String.valueOf(amount.getCurrency()
                        .getNumericCode());
            case NAME:
                return getCurrencyName(amount.getCurrency());
            case SYMBOL:
                // Fix for https://github.com/JavaMoney/jsr354-ri/issues/151
                if("BG".equals(locale.getCountry())){
                    return "лв";
                }
                return getCurrencySymbol(amount.getCurrency());
            default:
            case CODE:
                return amount.getCurrency().getCurrencyCode();
        }
    }