本文整理汇总了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();
}
示例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();
}
}
示例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();
}
示例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);
}
示例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();
}
示例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());
}
示例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;
}
示例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));
}
示例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));
}
示例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));
}