formats a number

@param number
@return formatted number as string
490886
public String format(Locale locale, double number) {
	DecimalFormat df = getDecimalFormat(locale);
	df.applyPattern(",0");
	df.setGroupingSize(3);
	return df.format(number);
    }
1219348
public static PrettyPrint indentWithSpaces(int number) {
    if (number < 0) {
      throw new IllegalArgumentException("number is negative");
    }
    char[] chars = new char[number];
    Arrays.fill(chars, ' ');
    return new PrettyPrint(chars);
  }
938534
public static function assertNumberFormat($number)
    {
        if (is_float($number)) {
            throw new \InvalidArgumentException(sprintf('The provided value "%s" must be a string, not a float.', $number));
        }
        if (!is_numeric($number)) {
            throw new \InvalidArgumentException(sprintf('The provided value "%s" is not a numeric value.', $number));
        }
    }
935475
public static String toStr(Number number) {
		if (null == number) {
			throw new NullPointerException("Number is null !");
		}

		if (false == ObjectUtil.isValidIfNumber(number)) {
			throw new IllegalArgumentException("Number is non-finite!");
		}

		// 去掉小数点儿后多余的0
		String string = number.toString();
		if (string.indexOf('.') > 0 && string.indexOf('e') < 0 && string.indexOf('E') < 0) {
			while (string.endsWith("0")) {
				string = string.substring(0, string.length() - 1);
			}
			if (string.endsWith(".")) {
				string = string.substring(0, string.length() - 1);
			}
		}
		return string;
	}
710254
def format_style(number: int) -> str:
    
    if str(number) not in _stylenums:
        raise InvalidStyle(number)
    return codeformat(number)
503246
public static String formatNumber(int num) {
        DecimalFormat format = new DecimalFormat();
        format.setDecimalSeparatorAlwaysShown(false);
        return format.format(num);
    }
664173
private StringBuffer format(double number, StringBuffer result, FieldPosition fieldPosition,
                                boolean parseAttr) {
        fieldPosition.setBeginIndex(0);
        fieldPosition.setEndIndex(0);

        if (Double.isNaN(number)) {
            if (fieldPosition.getField() == NumberFormat.INTEGER_FIELD) {
                fieldPosition.setBeginIndex(result.length());
            } else if (fieldPosition.getFieldAttribute() == NumberFormat.Field.INTEGER) {
                fieldPosition.setBeginIndex(result.length());
            }

            result.append(symbols.getNaN());
            // TODO: Combine setting a single FieldPosition or adding to an AttributedCharacterIterator
            // into a function like recordAttribute(FieldAttribute, begin, end).

            // [Spark/CDL] Add attribute for NaN here.
            // result.append(symbols.getNaN());
            if (parseAttr) {
                addAttribute(Field.INTEGER, result.length() - symbols.getNaN().length(),
                             result.length());
            }
            if (fieldPosition.getField() == NumberFormat.INTEGER_FIELD) {
                fieldPosition.setEndIndex(result.length());
            } else if (fieldPosition.getFieldAttribute() == NumberFormat.Field.INTEGER) {
                fieldPosition.setEndIndex(result.length());
            }

            addPadding(result, fieldPosition, 0, 0);
            return result;
        }

        // Do this BEFORE checking to see if value is negative or infinite and
        // before rounding.
        number = multiply(number);
        boolean isNegative = isNegative(number);
        number = round(number);

        if (Double.isInfinite(number)) {
            int prefixLen = appendAffix(result, isNegative, true, fieldPosition, parseAttr);

            if (fieldPosition.getField() == NumberFormat.INTEGER_FIELD) {
                fieldPosition.setBeginIndex(result.length());
            } else if (fieldPosition.getFieldAttribute() == NumberFormat.Field.INTEGER) {
                fieldPosition.setBeginIndex(result.length());
            }

            // [Spark/CDL] Add attribute for infinity here.
            result.append(symbols.getInfinity());
            if (parseAttr) {
                addAttribute(Field.INTEGER, result.length() - symbols.getInfinity().length(),
                             result.length());
            }
            if (fieldPosition.getField() == NumberFormat.INTEGER_FIELD) {
                fieldPosition.setEndIndex(result.length());
            } else if (fieldPosition.getFieldAttribute() == NumberFormat.Field.INTEGER) {
                fieldPosition.setEndIndex(result.length());
            }

            int suffixLen = appendAffix(result, isNegative, false, fieldPosition, parseAttr);

            addPadding(result, fieldPosition, prefixLen, suffixLen);
            return result;
        }

        int precision = precision(false);

        // This is to fix rounding for scientific notation. See ticket:10542.
        // This code should go away when a permanent fix is done for ticket:9931.
        //
        // This block of code only executes for scientific notation so it will not interfere with the
        // previous fix in {@link #resetActualRounding} for fixed decimal numbers.
        // Moreover this code only runs when there is rounding to be done (precision > 0) and when the
        // rounding mode is something other than ROUND_HALF_EVEN.
        // This block of code does the correct rounding of number in advance so that it will fit into
        // the number of digits indicated by precision. In this way, we avoid using the default
        // ROUND_HALF_EVEN behavior of DigitList. For example, if number = 0.003016 and roundingMode =
        // ROUND_DOWN and precision = 3 then after this code executes, number = 0.00301 (3 significant digits)
        if (useExponentialNotation && precision > 0 && number != 0.0 && roundingMode != BigDecimal.ROUND_HALF_EVEN) {
           int log10RoundingIncr = 1 - precision + (int) Math.floor(Math.log10(Math.abs(number)));
           double roundingIncReciprocal = 0.0;
           double roundingInc = 0.0;
           if (log10RoundingIncr < 0) {
               roundingIncReciprocal =
                       BigDecimal.ONE.movePointRight(-log10RoundingIncr).doubleValue();
           } else {
               roundingInc =
                       BigDecimal.ONE.movePointRight(log10RoundingIncr).doubleValue();
           }
           number = DecimalFormat.round(number, roundingInc, roundingIncReciprocal, roundingMode, isNegative);
        }
        // End fix for ticket:10542

        // At this point we are guaranteed a nonnegative finite
        // number.
        synchronized (digitList) {
            digitList.set(number, precision, !useExponentialNotation &&
                          !areSignificantDigitsUsed());
            return subformat(number, result, fieldPosition, isNegative, false, parseAttr);
        }
    }
817486
public static String formatBigDecimal(BigDecimal number) {
		if (number.signum() != -1) {
			return "+" + number.toString();
		} else {
			return number.toString();
		}
	}
331325
public static function normalizeNumber($number): string
    {
        $number = str_replace([',', ' '], ['.', ''], (string)$number);

        if (
            (($e = strrchr($number, 'e')) !== false) ||
            (($e = strrchr($number, 'E')) !== false)
        ) {
            $number = number_format((float)$number, -intval(substr($e, 1)));
        }

        return $number;
    }
155930
public static function format($number, $decimals = 2, $decimalPoint = '.', $thousandSeparator = ',')
    {
        return number_format($number, $decimals, $decimalPoint, $thousandSeparator);
    }
126346
def format_phone_number(number):
    
    if not isinstance(number, phonenumbers.PhoneNumber):
        number = phonenumbers.parse(number)
    return phonenumbers.format_number(number, phonenumbers.PhoneNumberFormat.INTERNATIONAL)
254409
private static final String toBrowserHexValue(final int number)
    {
        final String chex = Integer.toHexString(fixRGB(number) & 0xFF).toUpperCase();

        if (chex.length() < 2)
        {
            return "0" + chex;
        }
        return chex;
    }
394221
protected function cc_format($number, $options)
    {
        if (empty($number)) {
            return '';
        }

        switch ($options) {
            case 'two_digits':
                $number = sprintf("%02d", $number);
                return substr($number, -2);
                break;
            case 'four_digits':
                return sprintf("%04d", $number);
                break;
            default:
                return $number;
                break;
        }
    }
487109
public function numberFormat()
    {
        $num = (float) ((string) $this->getRequiredParameter('number'));
        $decimals = intval((string)$this->getParameter('decimals'));
        return number_format($num, $decimals);
    }
710691
public static String numberToString(Number n) throws JSONException {

        if (n == null) {
            throw new JSONException("Null pointer");
        }
        testValidity(n);

        // Shave off trailing zeros and decimal point, if possible.

        String s = n.toString();
        if ((s.indexOf('.') > 0) && (s.indexOf('e') < 0) && (s.indexOf('E') < 0)) {
            while (s.endsWith("0")) {
                s = s.substring(0, s.length() - 1);
            }
            if (s.endsWith(".")) {
                s = s.substring(0, s.length() - 1);
            }
        }
        return s;
    }
801309
public void setValue(Number number) {
		String txt = null;
		if (number != null) {
			txt = this.format.format(number);
		}
		setText(txt);
	}
95762
public function format($number) {
    if ((float) $number != $number) {
      throw new \InvalidArgumentException('Number has no valid float value.');
    }
    $sign = (int) ($number < 0);

    // Split the number in major and minor units, and make sure there is a
    // minor unit at all.
    $number = explode('.', abs($number));
    $number += array(
      self::MINOR => '',
    );

    $digits = array(
      str_split($number[self::MAJOR]),
      strlen($number[self::MINOR]) ? str_split($number[self::MINOR]) : array(),
    );

    $symbols = $this->cloneNumberPatternSymbols($this->symbols[$sign]);
    $this->process($symbols[$sign][self::MAJOR], $digits[self::MAJOR]);
    // Integer formatting defaults from right to left, but minor units should
    // be formatted from left to right, so reverse all data and results.
    $symbols_minor = array_reverse($symbols[$sign][self::MINOR]);
    $this->process($symbols_minor, array_reverse($digits[self::MINOR]));
    foreach ($symbols[$sign][self::MINOR] as $symbol) {
      if (!is_null($symbol->replacement)) {
        $symbol->replacement = strrev($symbol->replacement);
      }
    }

    // Prepare the output string.
    $output = array(
      self::MAJOR => '',
      self::MINOR => '',
    );
    foreach ($symbols[$sign] as $fragment => $fragment_symbols) {
      $this->replacePlaceholders($fragment_symbols);
      foreach ($fragment_symbols as $symbol) {
        $output[$fragment] .= !is_null($symbol->replacement) ? $symbol->replacement : $symbol->symbol;
      }
    }

    return $output[self::MAJOR] . $this->getReplacement(self::SYMBOL_SPECIAL_DECIMAL_SEPARATOR) . $output[self::MINOR];
  }