We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Java Currency Formatter
Java Currency Formatter
Sort by
recency
|
820 Discussions
|
Please Login in order to post a comment
This is so broken, don't bother doing in anything other then java 8. i think this question need changing for each verstion. this was every furstrating as i wasted 20 miuntes undering why my correct answer was wrong, even after changing the China: ¥ to the China: ¥ and the India: Rs.
I got my submission to pass by switching to Java 8 from java 15. But I left my workarounds for some of the problems. HackerRank shoul have different answers for the different Java versions, like they do with different SQL varieties.
Three differences: * Java 15 uses the Rupee symbol, but the answer wanted "Rm.". Had to create a custom currency fix for that. * Java 15 uses a different "Yen"/"Yuan" symbol than Java 8. * Java 15 uses a "NARROW NO-BREAK SPACE" (U+202F) code point for the grouping/thousands chaSPracter. The answer used a regular space character SPACE (U+0020).
This solution passes validation for Java 8
Indian format only worked as expected on the result in java 8
My code, when run, prints the Chinese yuan with two stikes on Y, while the expected output demands the yuan character with only one strike on Y. Hence, my code is not passing the test case.
Any suggestions are cited and welcome.
public class Solution {
double payment = scanner.nextDouble(); var u = NumberFormat.getCurrencyInstance(Locale.US); var i = NumberFormat.getCurrencyInstance(new Locale("en", "IN")); var c = NumberFormat.getCurrencyInstance(new Locale("zh","CN")); var f = NumberFormat.getCurrencyInstance(Locale.FRANCE); System.out.println("US: "+u.format(payment)); System.out.println("India: "+i.format(payment).replace(i.getCurrency().getSymbol(), "Rs.")); System.out.println("China: "+c.format(payment)); System.out.println("France: "+f.format(payment));
}