当前位置: 首页>>代码示例>>Java>>正文


Java RoundingMode.UP属性代码示例

本文整理汇总了Java中java.math.RoundingMode.UP属性的典型用法代码示例。如果您正苦于以下问题:Java RoundingMode.UP属性的具体用法?Java RoundingMode.UP怎么用?Java RoundingMode.UP使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在java.math.RoundingMode的用法示例。


在下文中一共展示了RoundingMode.UP属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: roundPriceToTickSize

/**
 * @param price        price to be rounded, has to be positive
 * @param roundingMode rounding mode that should be used (only {@link RoundingMode#UP} and {@link RoundingMode#DOWN}
 *                     are supported)
 * @return price rounded to tick size
 *
 * @throws IllegalArgumentException if {@code roundingMode} is neither {@link RoundingMode#UP} nor
 *                                  {@link RoundingMode#DOWN} or {@code price} is not positive
 */
static BigDecimal roundPriceToTickSize(final BigDecimal price, final RoundingMode roundingMode, final BigDecimal tickSize) {
    checkArgument(
        roundingMode == RoundingMode.UP || roundingMode == RoundingMode.DOWN,
        "Only rounding UP or DOWN supported"
    );
    checkArgument(price.compareTo(BigDecimal.ZERO) >= 0, "price=%s < 0", price);

    final BigDecimal remainder = price.remainder(tickSize);
    if (remainder.compareTo(BigDecimal.ZERO) == 0) {
        return price;
    }

    final BigDecimal result = price.subtract(remainder);
    if (roundingMode == RoundingMode.UP) {
        return result.add(tickSize);
    } else {
        return result;
    }
}
 
开发者ID:quedexnet,项目名称:java-market-maker,代码行数:28,代码来源:UniformFuturesOrderPlacingStrategy.java


注:本文中的java.math.RoundingMode.UP属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。