Advertisement
stevennathaniel

Format Currency Berupa Rupiah

Oct 28th, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package latihan30;
  7.  
  8. import java.math.BigDecimal;
  9.  
  10. import java.text.NumberFormat;
  11.  
  12. import java.util.Locale;
  13.  
  14. /**
  15.  *
  16.  * @author steven
  17.  */
  18. public class Uang2 {
  19.    
  20.     public static void main(String[] args){
  21.        
  22.         Locale indonesiaLocale = new Locale.Builder().setLanguage("in").setRegion("ID").build();
  23.        
  24.         BigDecimal amount = new BigDecimal(1000);
  25.        
  26.         // Format jumlah uang dalam format US yg merupakan default
  27.        
  28.         NumberFormat defaultFormat = NumberFormat.getCurrencyInstance();
  29.        
  30.         System.out.println("US: " + defaultFormat.format(amount));
  31.        
  32.        
  33.         // Format dalam Rp
  34.        
  35.         NumberFormat rupiahFormat = NumberFormat.getCurrencyInstance(indonesiaLocale);
  36.        
  37.         System.out.println("Indonesia: " + rupiahFormat.format(amount));
  38.        
  39.        
  40.     }
  41.    
  42.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement