Get the currency format for a country that does not have a Locale constant

前端 未结 6 1102
醉梦人生
醉梦人生 2020-12-29 02:44

I want to get the currency format of India, so I need a Locale object for India. But there exists only few a countries that have a Locale constant

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-29 03:02

    import java.text.NumberFormat;
    import java.util.Locale;
    
    double dbValue = 1_23_23_213.89;
    Locale lcl = new Locale("hi","IN");
    NumberFormat inFrmt = NumberFormat.getNumberInstance(lcl);
    System.out.println(inFrmt.format(dbValue));      //12,323,213.89
    
    NumberFormat cur = NumberFormat.getCurrencyInstance(lcl);
    System.out.println(cur.format(dbValue));      // ₹12,323,213.89
    

提交回复
热议问题