當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。