fucking decimal numbers into integer and decimal part

fukurou

hadouken
Administrator
#3
Java:
String doubleAsString = String.valueOf(5.899);
        int indexOfDecimal = doubleAsString.indexOf(".");
        // System.out.println("Double Number: " + doubleNumber);
        System.out.println("Integer Part: " + doubleAsString.substring(0, indexOfDecimal));
        System.out.println("Decimal Part: " + doubleAsString.substring(indexOfDecimal + 1));
output :
Integer Part: 5
Decimal Part: 899
 

fukurou

hadouken
Administrator
#8
Java:
public static boolean isDouble(String str) {
        return str.matches("\\d+\\.\\d+"); // match a number with optional "-" and decimal.
    }
check if string is a double
 

fukurou

hadouken
Administrator
#9
Java:
x.forEach { c ->
    if (c == '+') return@forEach
}
forEachIndexed if you care about index
x.forEachIndexed { index, c ->
    if (c == '+') {
        println("index=$index")
        return@forEachIndexed
    }
}
 
Top