Java Currency Formatter Changing $ to ¤

 Java currency formatting problem.

Following code shows the conditions when the currency symbol is replaced by an alt currency symbol.

public class Test {

    
    public static void main(String[] args){    
        double num = 1323.526;
        Locale eng = new Locale("", "");
        NumberFormat engFormat = NumberFormat.getCurrencyInstance(eng);
        System.out.println(engFormat.format(num));
        
        eng = new Locale("en", "");
        engFormat = NumberFormat.getCurrencyInstance(eng);
        System.out.println(engFormat.format(num));
        
        eng = new Locale("en", "en_US");
        engFormat = NumberFormat.getCurrencyInstance(eng);
        System.out.println(engFormat.format(num));
        
        eng = new Locale("", "US");
        engFormat = NumberFormat.getCurrencyInstance(eng);
        System.out.println(engFormat.format(num));
        
        
        eng = new Locale("en", "US");
        engFormat = NumberFormat.getCurrencyInstance(eng);
        System.out.println(engFormat.format(num));
        
        eng = new Locale("blah", "US");
        engFormat = NumberFormat.getCurrencyInstance(eng);
        System.out.println(engFormat.format(num));
                 
    }
}
    

Output :

¤ 1,323.53
¤1,323.53
¤1,323.53
USD 1,323.53
$1,323.53
USD 1,323.53

Comments

Popular posts from this blog

Delete horizontal, vertical and angled lines from an image using Python to clear noise and read text with minimum errors

Unordered JSON compare for differences using javascript