Transformer method. Format currency using specified parameters
@param template
@param data
@param currencyCode
@return the currency string
See {@link #formatCurrency(org.rythmengine.template.ITemplate, Object, String, java.util.Locale)}
338676
public static String formatCurrency(ITemplate template, Object data, String currencyCode) {
        return formatCurrency(template, data, currencyCode, null);
    }
304201
public static MonetaryAmountDecimalFormatBuilder of(Locale locale) {
        MonetaryAmountDecimalFormatBuilder builder = new MonetaryAmountDecimalFormatBuilder();
        builder.decimalFormat = (DecimalFormat) NumberFormat.getCurrencyInstance(locale);
        builder.locale = locale;
        return builder;
    }
668300
public static CurrencyFunction currency(Field field, @Nullable String currencyCode) {

		Assert.notNull(field, "Field for currency function must not be 'null'.");

		CurrencyFunction function = new CurrencyFunction(field);
		if (StringUtils.hasText(currencyCode)) {
			function.addArgument(currencyCode);
		}
		return function;
	}
455011
public TypeSpec createCurrencyUtil(String className, Map<String, CurrencyData> currencies) {
    TypeSpec.Builder type = TypeSpec.classBuilder(className)
        .addModifiers(Modifier.PUBLIC);
    
    CurrencyData defaultData = currencies.get("DEFAULT");
    currencies.remove("DEFAULT");
    
    MethodSpec.Builder code = MethodSpec.methodBuilder("getCurrencyDigits")
        .addModifiers(PUBLIC, STATIC)
        .addParameter(Types.CLDR_CURRENCY_ENUM, "code")
        .returns(int.class);
    
    code.beginControlFlow("switch (code)");
    for (Map.Entry<String, CurrencyData> entry : currencies.entrySet()) {
      CurrencyData data = entry.getValue();
      code.addStatement("case $L: return $L", entry.getKey(), data.digits);
    }
    code.addStatement("default: return $L", defaultData.digits);
    code.endControlFlow();
    
    type.addMethod(code.build());
    return type.build();
  }
277752
public void formatCurrency(
      BigDecimal n, CLDR.Currency currencyCode, StringBuilder destination, CurrencyFormatOptions options) {
    
    DigitBuffer dbuf = new DigitBuffer();
    CurrencyFormatStyle style = options.style();
    NumberFormatMode formatMode = orDefault(options.formatMode(), NumberFormatMode.DEFAULT);
    boolean grouping = orDefault(options.grouping(), true);
    int currencyDigits = getCurrencyDigits(currencyCode);

    switch (style) {
      case SYMBOL:
      case ACCOUNTING:
      {
        NumberPattern[] patterns = style == CurrencyFormatStyle.SYMBOL ? currencyStandard : currencyAccounting;
        NumberPattern pattern = select(n, patterns);
        String symbol = options.symbolWidth() == CurrencySymbolWidth.NARROW 
            ? getNarrowCurrencySymbol(currencyCode) : getCurrencySymbol(currencyCode);
        DigitBuffer other = new DigitBuffer();
        setup(params, pattern, n, other, options, symbol, formatMode, grouping, currencyDigits, -1, -1);
        format(pattern, other, dbuf, symbol, null);
        dbuf.appendTo(destination);
        break;
      }

      case SHORT:
      {
        NumberFormatContext ctx = new NumberFormatContext(options, SIGNIFICANT_MAXFRAC, currencyDigits);
        int nDigits = integerDigits(n);
        int nDivisor = getDivisor_CURRENCY_SHORT(nDigits);

        // Q1 is the number divided by the divisor (if any).
        BigDecimal q1 = n;
        if (nDivisor > 0) {
          q1 = n.movePointLeft(nDivisor).stripTrailingZeros();
        }
        int q1Digits = integerDigits(q1);

        // Select an initial pattern using the OTHER plural category.
        NumberPattern pattern = select(n, getPattern_CURRENCY_SHORT(nDigits, PluralCategory.OTHER));
        
        // Q2 is the number adjusted using the pattern and options.
        ctx.setCompact(pattern, q1Digits, nDivisor);
        BigDecimal q2 = ctx.adjust(q1);
        int q2Digits = integerDigits(q2);

        // Number rounded up, we need to select a new divisor and pattern.
        if (q2Digits > q1Digits) {
          // Bump the number of digits by 1 to select the next divisor/pattern.
          nDigits++;
          int divisor = getDivisor_CURRENCY_SHORT(nDigits);
          pattern = select(n, getPattern_CURRENCY_SHORT(nDigits, PluralCategory.OTHER));
          
          // If divisor changed, we need to divide and adjust again. 
          // Otherwise we just use Q2 as-is.
          if (divisor > nDivisor) {
            q1 = n.movePointLeft(divisor).stripTrailingZeros();
            ctx.setCompact(pattern, integerDigits(q1), divisor);
            q2 = ctx.adjust(q1);
          }
        }

        // Compute the plural category.
        NumberOperands operands = new NumberOperands(q2.toPlainString());
        PluralCategory category = PLURAL_RULES.evalCardinal(bundleId.language(), operands);

        // Select the final pluralized pattern.
        pattern = select(n, getPattern_CURRENCY_SHORT(nDigits, category));
        
        // Format the number into the buffer.
        String symbol = getCurrencySymbol(currencyCode);
        DigitBuffer number = new DigitBuffer();
        NumberFormattingUtils.format(q2, number, params, true, grouping, 
            pattern.format.minimumIntegerDigits,
            currencyStandard[0].format.primaryGroupingSize, 
            currencyStandard[0].format.secondaryGroupingSize);
        
        // Format the entire pattern and append to destination.
        format(pattern, number, dbuf, symbol, null);
        dbuf.appendTo(destination);
        break;
      }
      
      case NAME:
      case CODE:
      {
        // Format the number with generic formatter parameters and grouping off to get the plural category.
        NumberPattern pattern = select(n, decimalStandard);
        DigitBuffer number = new DigitBuffer();
        setup(GENERIC_PARAMS, pattern, n, number, options, null, formatMode, false, currencyDigits, -1, -1);
        
        // Set the operands and get the plural category.
        NumberOperands operands = new NumberOperands(number);
        PluralCategory category = PLURAL_RULES.evalCardinal(bundleId.language(), operands);
        number.reset();

        // Format the number
        setup(params, pattern, n, number, options, null, formatMode, grouping, currencyDigits, -1, -1);
        format(pattern, number, dbuf, null, null);
        
        // Wrap the result with the wrapper selected by the plural category.
        String unit = style == CurrencyFormatStyle.CODE 
            ? currencyCode.toString() 
            : getCurrencyPluralName(currencyCode, category);
        wrapUnits(category, dbuf, unit, destination);
        break;
      }
    }
  }
1114854
public java.lang.String getCurrencyCode() {
    java.lang.Object ref = currencyCode_;
    if (ref instanceof java.lang.String) {
      return (java.lang.String) ref;
    } else {
      com.google.protobuf.ByteString bs = 
          (com.google.protobuf.ByteString) ref;
      java.lang.String s = bs.toStringUtf8();
      currencyCode_ = s;
      return s;
    }
  }
298656
public static CurrencyFunction currency(String fieldName, @Nullable String currencyCode) {

		Assert.hasText(fieldName, "FieldName for currency function must not be 'empty'.");
		return currency(new SimpleField(fieldName), currencyCode);
	}
44557
public static String formatPluralCurrency(final Number value, final Locale locale)
    {
        return withinLocale(new Callable<String>()
        {
            public String call() throws Exception
            {
                return formatPluralCurrency(value);
            }
        }, locale);
    }
868922
private String formatCurrency(Number value)
   {
      return (value == null ? null : m_formats.getCurrencyFormat().format(value));
   }
1167556
public com.google.protobuf.ByteString
      getCurrencyCodeBytes() {
    java.lang.Object ref = currencyCode_;
    if (ref instanceof java.lang.String) {
      com.google.protobuf.ByteString b = 
          com.google.protobuf.ByteString.copyFromUtf8(
              (java.lang.String) ref);
      currencyCode_ = b;
      return b;
    } else {
      return (com.google.protobuf.ByteString) ref;
    }
  }
64479
public static CurrencyFunction currency(String fieldName) {

		Assert.hasText(fieldName, "FieldName must not be empty!");
		return currency(fieldName, null);
	}
22909
@Override
    public Set<CurrencyUnit> getCurrencies(CurrencyQuery query) {
        Set<CurrencyUnit> result = new HashSet<>();
        for (Locale locale : query.getCountries()) {
            try {
                result.add(Waehrung.of(Currency.getInstance(locale)));
            } catch (IllegalArgumentException ex) {
                LOG.log(Level.WARNING, "Cannot get currency for locale '" + locale + "':", ex);
            }
        }
        for (String currencyCode : query.getCurrencyCodes()) {
            try {
                result.add(Waehrung.of(currencyCode));
            } catch (IllegalArgumentException ex) {
                LOG.log(Level.WARNING, "Cannot get currency '" + currencyCode + "':", ex);
            }
        }
        for (CurrencyProviderSpi spi : Bootstrap.getServices(CurrencyProviderSpi.class)) {
            result.addAll(spi.getCurrencies(query));
        }
        return result;
    }
175524
private void parseCurrencyData(LocaleID id, String code, JsonObject root) {
    NumberData data = getNumberData(id);
    data.currencySymbols = new LinkedHashMap<>();
    data.narrowCurrencySymbols = new LinkedHashMap<>();
    data.currencyDisplayName = new LinkedHashMap<>();
    data.currencyDisplayNames = new LinkedHashMap<>();
    JsonObject currencies = resolve(root, "numbers", "currencies");
    for (String currencyCode : objectKeys(currencies)) {
      JsonObject node = resolve(currencies, currencyCode);

      data.currencyDisplayName.put(currencyCode, string(node, "displayName"));
      String symbol = string(node, "symbol");
      String narrowSymbol = string(node, "symbol-alt-narrow");
      narrowSymbol = narrowSymbol.equals("") ? symbol : narrowSymbol;
      data.currencySymbols.put(currencyCode, symbol);
      data.narrowCurrencySymbols.put(currencyCode, narrowSymbol);

      Map<String, String> displayNames = new LinkedHashMap<>();
      for (String key : objectKeys(node)) {
        if (key.startsWith("displayName-count")) {
          displayNames.put(key, node.get(key).getAsString());
        }
      }
      data.currencyDisplayNames.put(currencyCode, displayNames);
    }
  }
199631
public MonetaryFormat code(int codeShift, String code) {
        checkArgument(codeShift >= 0);
        final String[] codes = null == this.codes
            ? new String[MAX_DECIMALS]
            : Arrays.copyOf(this.codes, this.codes.length);

        codes[codeShift] = code;
        return new MonetaryFormat(negativeSign, positiveSign, zeroDigit, decimalMark, minDecimals, decimalGroups,
                shift, roundingMode, codes, codeSeparator, codePrefixed);
    }
390562
private static Currency createCurrency(
      String commonCode, String name, String unicode, String... alternativeCodes) {

    CurrencyAttributes attributes =
        new CurrencyAttributes(commonCode, name, unicode, alternativeCodes);

    Currency currency = new Currency(commonCode, attributes);

    for (String code : attributes.codes) {
      if (commonCode.equals(code)) {
        // common code will always be part of the currencies map

        currencies.put(code, currency);

      } else if (!currencies.containsKey(code)) {
        // alternative codes will never overwrite common codes

        currencies.put(code, new Currency(code, attributes));
      }
    }

    return currency;
  }
647020
public function format(
        $price,
        $digits = null,
        $locale = null,
        $currency = null,
        $currencyPosition = self::CURRENCY_LOCATION_NONE
    ) {
        if (is_null($locale)) {
            $locale = $this->defaultLocale;
        }

        if (is_null($digits)) {
            $digits = $this->defaultDigits;
        }

        $formatter = $this->getFormatter($locale, $digits);
        $formattedPrice = $formatter->format($price);

        if ($currencyPosition != self::CURRENCY_LOCATION_NONE && is_null($currency)) {
            throw new PriceFormatterException('currency must be set, if location is set');
        }

        switch ($currencyPosition) {
            case self::CURRENCY_LOCATION_PREFIX:
                $formattedPrice = $currency . ' ' . $formattedPrice;
                break;
            case self::CURRENCY_LOCATION_SUFFIX:
                $formattedPrice = $formattedPrice . ' ' . $currency;
                break;
        }

        return $formattedPrice;
    }
814737
public static CurrencyUnitBuilder of(String currencyCode, String providerName) {
        return new CurrencyUnitBuilder(currencyCode, CurrencyContextBuilder.of(providerName).build());
    }