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


Java DoubleMath.isMathematicalInteger方法代码示例

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


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

示例1: formatDoubleSpecialSmart

import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
@Override
protected String formatDoubleSpecialSmart(Double value) {
    BigDecimal bigDecimal = BigDecimal.valueOf(value);

    // do not do this for math integers
    if (!DoubleMath.isMathematicalInteger(value)) {
        // precision is just like in graphite (scale check redundant but let it be)
        if (bigDecimal.precision() > 12 && bigDecimal.scale() > 0) {
            int roundTo = bigDecimal.scale() - bigDecimal.precision() + 12 > 0 ? bigDecimal.scale() - bigDecimal.precision() + 12 : 0;
            bigDecimal = bigDecimal.setScale(roundTo, BigDecimal.ROUND_HALF_UP);
        }
    }


    return (bigDecimal.precision() + bigDecimal.scale() > 12) ?
            bigDecimal.stripTrailingZeros().toEngineeringString() : bigDecimal.stripTrailingZeros().toPlainString();

}
 
开发者ID:EinsamHauer,项目名称:disthene-reader,代码行数:19,代码来源:MachineValueFormatter.java

示例2: formatValue

import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
@Nonnull
public static String formatValue(@Nonnull Object value) {
  if (value instanceof Double) {
    Double doubleValue = (Double) value;

    // String.format is very expensive, so avoid it for whole numbers that can fit in Long.
    // We simply append ".00000" to long, in order to keep the existing behavior.
    if (doubleValue <= Long.MAX_VALUE && DoubleMath.isMathematicalInteger(doubleValue)) {
      return Long.toString(doubleValue.longValue()) + ".00000";
    } else {
      return String.format(Locale.US, "%1.5f", doubleValue);
    }
  } else {
    return value.toString();
  }
}
 
开发者ID:linkedin,项目名称:pinot,代码行数:17,代码来源:AggregationFunctionUtils.java

示例3: asInt

import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
static
public int asInt(Number number){

	if(number instanceof Integer){
		return (Integer)number;
	}

	double value = number.doubleValue();

	if(DoubleMath.isMathematicalInteger(value)){
		return Ints.checkedCast((long)value);
	}

	throw new IllegalArgumentException();
}
 
开发者ID:jpmml,项目名称:jpmml-converter,代码行数:16,代码来源:ValueUtil.java

示例4: toUnsignedLong

import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
static
UnsignedLong toUnsignedLong(double value){

	if(!DoubleMath.isMathematicalInteger(value)){
		throw new IllegalArgumentException();
	}

	return UnsignedLong.fromLongBits((long)value);
}
 
开发者ID:jpmml,项目名称:jpmml-r,代码行数:10,代码来源:RandomForestConverter.java

示例5: formatDoubleSpecialPlain

import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
public static String formatDoubleSpecialPlain(Double value) {
    BigDecimal bigDecimal = BigDecimal.valueOf(value);

    // do not do this for math integers
    if (!DoubleMath.isMathematicalInteger(value)) {
        // precision is just like in graphite (scale check redundant but let it be)
        if (bigDecimal.precision() > 12 && bigDecimal.scale() > 0) {
            int roundTo = bigDecimal.scale() - bigDecimal.precision() + 12 > 0 ? bigDecimal.scale() - bigDecimal.precision() + 12 : 0;
            bigDecimal = bigDecimal.setScale(roundTo, BigDecimal.ROUND_HALF_UP);
        }
    }


    return bigDecimal.stripTrailingZeros().toPlainString();
}
 
开发者ID:EinsamHauer,项目名称:disthene-reader,代码行数:16,代码来源:GraphiteUtils.java

示例6: formatDoubleSpecialSmart

import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
@Override
protected String formatDoubleSpecialSmart(Double value) {
    BigDecimal bigDecimal = BigDecimal.valueOf(value);

    // do not do this for math integers
    if (!DoubleMath.isMathematicalInteger(value)) {
        // precision is just like in graphite (scale check redundant but let it be)
        if (bigDecimal.precision() > 12 && bigDecimal.scale() > 0) {
            int roundTo = bigDecimal.scale() - bigDecimal.precision() + 12 > 0 ? bigDecimal.scale() - bigDecimal.precision() + 12 : 0;
            bigDecimal = bigDecimal.setScale(roundTo, BigDecimal.ROUND_HALF_UP);
        }
    }

    return formatter.format(bigDecimal.doubleValue());
}
 
开发者ID:EinsamHauer,项目名称:disthene-reader,代码行数:16,代码来源:HumanValueFormatter.java

示例7: getDataType

import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
static
public DataType getDataType(List<String> values){
	DataType dataType = DataType.INTEGER;

	for(String value : values){

		switch(dataType){
			case INTEGER:
				try {
					Integer.parseInt(value);

					continue;
				} catch(NumberFormatException integerNfe){

					try {
						double doubleValue = Double.parseDouble(value);

						if(DoubleMath.isMathematicalInteger(doubleValue)){
							continue;
						}

						dataType = DataType.DOUBLE;
					} catch(NumberFormatException doubleNfe){
						dataType = DataType.STRING;
					}
				}
				// Falls through
			case DOUBLE:
				try {
					Double.parseDouble(value);

					continue;
				} catch(NumberFormatException nfe){
					dataType = DataType.STRING;
				}
				// Falls through
			default:
				break;
		}
	}

	return dataType;
}
 
开发者ID:jpmml,项目名称:jpmml-lightgbm,代码行数:44,代码来源:LightGBMUtil.java

示例8: getPriceString

import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
private String getPriceString(double price) {
    return (DoubleMath.isMathematicalInteger(price) ? Integer.toString((int) price) : Double.toString(price));
}
 
开发者ID:elsiff,项目名称:MoreFish,代码行数:4,代码来源:FishShopGUI.java

示例9: toString

import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
/**
 * Gets the amount as a string.
 * <p>
 * The format is the currency code, followed by a space, followed by the
 * amount: '${currency} ${amount}'.
 *
 * @return the currency amount
 */
@Override
@ToString
public String toString() {
  return currency + " " +
      (DoubleMath.isMathematicalInteger(amount) ? Long.toString((long) amount) : Double.toString(amount));
}
 
开发者ID:OpenGamma,项目名称:Strata,代码行数:15,代码来源:CurrencyAmount.java

示例10: toString

import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
/**
 * Returns the formatted string version of the currency pair.
 * <p>
 * The format is '${baseCurrency}/${counterCurrency} ${rate}'.
 * 
 * @return the formatted string
 */
@Override
public String toString() {
  return pair + " " + (DoubleMath.isMathematicalInteger(rate) ? Long.toString((long) rate) : Double.toString(rate));
}
 
开发者ID:OpenGamma,项目名称:Strata,代码行数:12,代码来源:FxRate.java


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