Answer to Question #324576 in Java | JSP | JSF for Michael Parenas

Question #324576

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.

1
Expert's answer
2022-04-06T05:07:32-0400
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);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS