Chapter03 国际化(二) 数字格式
来源:互联网 发布:空气净化器有用吗 知乎 编辑:程序博客网 时间:2024/05/22 03:11
对于不同的国家,货币和数字表示方式不同,这就需要数据格式转化。
我们分为的三个步骤来解析:
1.得到Locale对象,即需要转化为哪个国家的
2.使用工厂模式获取格式化器对象
3.使用格式化器对象转化
测试代码如下图:
@Testpublic void test2() throws ParseException{//1.得到Locale对象Locale locale=new Locale(Locale.FRENCH.getLanguage(),Locale.FRANCE.getCountry());//2.使用工厂方法获取格式化器对象NumberFormat numberFormat=NumberFormat.getNumberInstance(locale);NumberFormat currencyFormat=NumberFormat.getCurrencyInstance(locale);NumberFormat fmt=NumberFormat.getPercentInstance();//3.使用格式化器来进行解析String s=numberFormat.format(1232.78);//将货币转化为法郎String money=currencyFormat.format(1222334);System.out.println(s);System.out.println(money);//将字符串解析为数字,可能会抛出异常Number num=currencyFormat.parse(money);System.out.println(num.doubleValue());//百分数转化String percent=fmt.format(0.4);System.out.println(percent);}对于NumberFormat的各个方法:
@Testpublic void test2() throws ParseException{//1.得到Locale对象Locale locale=new Locale(Locale.FRENCH.getLanguage(),Locale.FRANCE.getCountry());//2.使用工厂方法获取格式化器对象NumberFormat numberFormat=NumberFormat.getNumberInstance(locale);NumberFormat currencyFormat=NumberFormat.getCurrencyInstance(locale);NumberFormat fmt=NumberFormat.getPercentInstance();//3.使用格式化器来进行解析String s=numberFormat.format(1232.78);//将货币转化为法郎String money=currencyFormat.format(1222334);System.out.println(s);System.out.println(money);//将字符串解析为数字,可能会抛出异常Number num=currencyFormat.parse(money);System.out.println(num.doubleValue());//百分数转化String percent=fmt.format(0.4);System.out.println(percent);//为法国人设置澳元格式currencyFormat.setCurrency(Currency.getInstance(Locale.CANADA));//打印出2 344 233 242,00 CADString doller=currencyFormat.format(2344233242L);System.out.println(doller);}
阅读全文
0 0
- Chapter03 国际化(二) 数字格式
- Chapter03 国际化(四) 排序
- Chapter03 国际化(一) Locale类
- Chapter03 国际化(五) 消息格式化
- Chapter03 国际化(六) 资源包
- Chapter03 国际化(三) 日期和时间
- 国际化数字格式输出(C#版)
- java国际化——Locale+数字格式
- web国际化日期显示及数字格式
- 国际化-数字格式化
- 日期格式国际化
- Struts国际化处理 二
- jsf学习二(国际化)
- fmt 国际化格式标签库
- fmt 国际化格式标签库
- fmt 国际化格式标签库
- fmt 国际化格式标签库
- Practical_RichFaces要点Chapter03
- 浅谈解决浏览器不执行javascript的问题(sf.gg也发表了一份)
- Linux学习笔记(2)_用户,用户组,文件权限
- SXSSFWorkbook导出大数据量Excel文件
- 数理逻辑2 -- 量化理论5
- HDU 3790 简单最短路径问题(dijkstra+双重权值)
- Chapter03 国际化(二) 数字格式
- Android内存解析<二>
- android 编译错误 Error:(1, 0) Plugin with id 'com.android.application' not found. 解决
- 如何入门 Python 爬虫?
- VLC 集成
- 机器学习(十六)
- sublime快捷键使用
- 五分钟学GIS | GPU在GIS技术上的应用
- javascript读写json示例