Sunday, May 28, 2017

Format String value up to 2 decimal place in Java



public static String formatStringUpto2DigitDecimal(String orig) {

    String newValue =  orig.substring(orig.indexOf("."));
    if(newValue.length() > 3){
        System.out.println("newValue : " + newValue + " New : " + newValue.substring(0,3));
        return orig.substring(0,orig.indexOf(".")).concat(newValue.substring(0,3));
    }

    return orig;
}

No comments:

Post a Comment