convert int To String with NumberFormat - Java java.lang

Java examples for java.lang:int Format

Description

convert int To String with NumberFormat

Demo Code

//package com.java2s;
import java.text.NumberFormat;

public class Main {
    public static void main(String[] argv) {
        double value = 42.45678;
        System.out.println(convertToString(value));
    }/*from   w  ww. j a v  a2 s  . c  o  m*/

    /**
     * @param value
     * @return
     */
    public static String convertToString(double value) {
        return convertToString((int) value);
    }

    /**
     * @param value
     * @return
     */
    public static String convertToString(int value) {
        return "$" + NumberFormat.getInstance().format(value);
    }
}

Related Tutorials