Create a short program that will print 123467.89 as currency using NumberFormat.
Sample Output:
------------------------------------------------------------------
I have ₱1,234,567.89 in my bank account.
import java.util.Scanner;
public class Testing {
public static void numberFormat(double num){
String namStr = "";
if(num > 1000000)
namStr += (int) num/1000000 + " ";
if(num > 1000)
namStr += (int) num/1000 + " ";
namStr += (int) num%1000;
System.out.printf("%s,%.0f", namStr, ((num - (int) num)*100));
}
public static void main(String[] args){
Scanner in = new Scanner(System.in);
double ch = in.nextDouble();
numberFormat(ch);
}
}
Comments
Leave a comment