- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathJavaCurrencyFormatter.java
More file actions
Latest commit
34 lines (27 loc) · 1.18 KB
/
Copy pathJavaCurrencyFormatter.java
File metadata and controls
34 lines (27 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// https://www.hackerrank.com/challenges/java-currency-formatter/problem
importjava.text.NumberFormat;
importjava.util.Locale;
importjava.util.Scanner;
publicclassJavaCurrencyFormatter {
publicstaticvoidmain(String[] args) {
Scannerscanner = newScanner(System.in);
doublevalue = scanner.nextDouble();
scanner.close();
System.out.println("US: " + toAmericanFormat(value));
System.out.println("India: " + toIndianFormat(value));
System.out.println("China: " + toChineseFormat(value));
System.out.println("France: " + toFrenchFormat(value));
}
privatestaticStringtoFrenchFormat(doublevalue) {
returnNumberFormat.getCurrencyInstance(Locale.FRANCE).format(value);
}
privatestaticStringtoAmericanFormat(doublevalue) {
returnNumberFormat.getCurrencyInstance(Locale.US).format(value);
}
privatestaticStringtoIndianFormat(doublevalue) {
return"Rs." + NumberFormat.getCurrencyInstance(Locale.US).format(value).substring(1);
}
privatestaticStringtoChineseFormat(doublevalue) {
returnNumberFormat.getCurrencyInstance(Locale.CHINA).format(value);
}
}