code: protected void format(
        NumberPattern pattern,
        DigitBuffer number,
        DigitBuffer buf,
        String currency,
        String percent) {
  
      // Flag indicating if we've emitted the formatted number yet.
      boolean emitted = false;
  
      // Iterate over the nodes in the format, handling each type.
      List<Node> nodes = pattern.parsed();
      int size = nodes.size();
      for (int i = 0; i < size; i++) {
        Node node = nodes.get(i);
        if (node instanceof Text) {
          buf.append(((Text)node).text());
  
        } else if (node instanceof Format) {
          buf.append(number);
          emitted = true;
  
        } else if (node instanceof Symbol) {
          switch ((Symbol)node) {
            case MINUS:
              buf.append(params.minus);
              break;
  
            case PERCENT:
              if (percent != null) {
                buf.append(percent);
              }
              break;
  
            case CURRENCY:
              if (currency == null || currency.isEmpty()) {
                break;
              }
  
              // Spacing around currency depending on if it occurs before or
              // after the formatted digits.
              if (emitted) {
                char firstCh = currency.charAt(0);
                if (!isSymbol(firstCh) && Character.isDigit(buf.last())) {
                  buf.append(NBSP);
                }
                buf.append(currency);
  
              } else {
                buf.append(currency);
                boolean nextFormat = i < (size - 1) && nodes.get(i + 1) instanceof Format;
                char lastCh = currency.charAt(currency.length() - 1);
                if (!isSymbol(lastCh) && nextFormat) {
                  buf.append(NBSP);
                }
              }
              break;
          }
        }
      }
    }
docs: Formats a number using a pattern and options.