矩阵包含十进制类型的值?

时间:2022-01-15 17:09:20

hello I have the following matrix: how do I check that contains decimal data type?

你好,我有以下矩阵:我如何检查包含十进制数据类型?

 int row =10;
 int column = 10;
 Object[][] m= new Object[rows][column]

3 个解决方案

#1


1  

If you create an Object array you can store any types of objects in there. You can check for any given given value if it is numeric and capable of representing decimals:

如果创建Object数组,则可以在其中存储任何类型的对象。您可以检查任何给定的给定值,如果它是数字并且能够表示小数:

public static boolean isDecimalValue(Object value) {
    return value != null && 
        (value instanceof Double || 
         value instanceof Float ||
         value instanceof BigDecimal
        );
}

Usage:

System.out.println(isDecimalValue(42)); // false
System.out.println(isDecimalValue(6.666d)); // true
System.out.println(isDecimalValue("potato")); // false
System.out.println(isDecimalValue(null)); // false
System.out.println(isDecimalValue(new BigDecimal("3.141592653589793"))); // true

#2


0  

You can use instanceof operator. This link may help you.

您可以使用instanceof运算符。这个链接可以帮到你。

#3


0  

if (obj instanceof Double){ //logic}

if(obj instanceof Double){//逻辑}

#1


1  

If you create an Object array you can store any types of objects in there. You can check for any given given value if it is numeric and capable of representing decimals:

如果创建Object数组,则可以在其中存储任何类型的对象。您可以检查任何给定的给定值,如果它是数字并且能够表示小数:

public static boolean isDecimalValue(Object value) {
    return value != null && 
        (value instanceof Double || 
         value instanceof Float ||
         value instanceof BigDecimal
        );
}

Usage:

System.out.println(isDecimalValue(42)); // false
System.out.println(isDecimalValue(6.666d)); // true
System.out.println(isDecimalValue("potato")); // false
System.out.println(isDecimalValue(null)); // false
System.out.println(isDecimalValue(new BigDecimal("3.141592653589793"))); // true

#2


0  

You can use instanceof operator. This link may help you.

您可以使用instanceof运算符。这个链接可以帮到你。

#3


0  

if (obj instanceof Double){ //logic}

if(obj instanceof Double){//逻辑}