import java.util.*;

import java.text.*;

/*

nowjava - 时代Java 提 供

*/

public class DecimalFormatDemo {

static public void customFormat(String pattern, double value) {

DecimalFormat myFormatter = new DecimalFormat(pattern);

String output = myFormatter.format(value);

System.out.println(value + " " + pattern + " " + output);

}

static public void localizedFormat(String pattern, double value,

Locale loc) {

NumberFormat nf = NumberFormat.getNumberInstance(loc);

DecimalFormat df = (DecimalFormat) nf;

df.applyPattern(pattern);

String output = df.format(value);

System.out.println(pattern + " " + output + " " + loc.toString());

}

/*来自 n o w j a v a . c o m - 时 代 Java*/

static public void main(String[] args) {

customFormat("###,###.###", 123456.789);

customFormat("###.##", 123456.789);

customFormat("000000.000", 123.78);

customFormat("$###,###.###", 12345.67);

customFormat("\u00a5###,###.###", 12345.67);

Locale currentLocale = new Locale("en", "US");

DecimalFormatSymbols unusualSymbols = new DecimalFormatSymbols(

currentLocale);

unusualSymbols.setDecimalSeparator('|');

unusualSymbols.setGroupingSeparator('^');

String strange = "#,##0.###";

DecimalFormat weirdFormatter = new DecimalFormat(strange,

unusualSymbols);

weirdFormatter.setGroupingSize(4);

String bizarre = weirdFormatter.format(12345.678);

System.out.println(bizarre);

Locale[] locales = { new Locale("en", "US"),

new Locale("de", "DE"), new Locale("fr", "FR") };

for (int i = 0; i < locales.length; i++) {

localizedFormat("###,###.###", 123456.789, locales[i]);

}

}

}

/*

* Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.

*

* Redistribution and use in source and binary forms, with or without

* modification, are permitted provided that the following conditions

* are met:

*

* - Redistributions of source code must retain the above copyright

* notice, this list of conditions and the following disclaimer.

*

* - Redistributions in binary form must reproduce the above copyright

* notice, this list of conditions and the following disclaimer in the

* documentation and/or other materials provided with the distribution.

*

* - Neither the name of Oracle or the names of its

* contributors may be used to endorse or promote products derived

* from this software without specific prior written permission.

*

* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS

* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,

* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR

/**代码未完, 请加载全部代码(NowJava.com).**/

java中自定义输入数字格式_Java 创建并使用自定义数字格式、35;###、####.#####和语言环境...相关推荐

  1. java中的输入输出流概念_java输入输出--I/O流的概念和划分

    理解数据流 数据流(Stream)是一组有顺序的,有起点的,有终点的字节集合,是对输入和输出的总称和抽象. 一般地,数据流分为 输入流(InputStream)和输出流(OutputStream).输 ...

  2. 在java中如何输入_java如何输入

    ❶ java 如何从键盘上接受输入 public class import { public static void main(String[] args) { System.out.println( ...

  3. java中的in的语法_java的输入语法

    同学,你好 c语言面向过程 而java面向对象 所以用java做事前肯定要先创建对象啦 java中的输入语句 先创建Scanner对象 Scanner对象 Scanner sc = new Scann ...

  4. Java中如何输入一个字符串

    Java中如何输入一个字符串 首先需导入java.util包中的Scanner类,如图: 接着在main里创建Scanner类对象,记得要把System.in加上这是专门获取用户输入的内容的,它会交给 ...

  5. Java中键盘输入一个数组的具体操作及说明

    在java中需要输入一个数组,再对输入的数组进行一些基本操作.这里给出了"(2)键盘输入一个数组:(2)计算数组和:(3)计算数组中的最大值 "的完整代码. import java ...

  6. java中判断日期是当天_java中如何判断指定日期是不是今天

    java中如何判断指定日期是不是今天 发布时间:2020-06-19 10:35:23 来源:亿速云 阅读:150 作者:Leah java中如何判断指定日期是不是今天?相信很多新手小白还没学会这个技 ...

  7. 禅道设置bug模板_禅道的自定义功能:表格切换和创建页面的自定义

    原标题:禅道的自定义功能:表格切换和创建页面的自定义 禅道8.2beta版本开始,增强了自定义功能. 用户可以根据自己的使用需要个性化设置禅道页面所显示的功能模块和字段. 可自定义的项如下: 导航菜单 ...

  8. java中输出时 什么作用_JAVA中输入和输出处理(Java I/O)重点总结

    文件-使用File类操作文件: 什么是文件?  文件可认为是相关记录或放在一起的数据的集合. 文件一般存储在哪里?  储存在存储设备里. Java程序如何访问文件?  Java API:java.io ...

  9. java中的方法使用方法_Java 中方法的创建与使用

    在Java 中 除了字段来表示某种类型的基本数据,还有方法来表示类中的请求,或者说是动作.Java中用方法决定了一个对象能接受什么样的信息 做出什么样的动作. 方法的基本组成有 名字 参数 返回值 还 ...

最新文章

  1. 对业务系统的监控 No.118
  2. JavaScript系列-----对象基于哈希存储(Key,Value之Key篇) (1)
  3. 大多数日志文件的后缀名是_编程小短文:find,让你随心所欲查找整块磁盘的任意文件...
  4. dl 系列服务器,DL系列服务器内存总结..doc
  5. Bash数组变量的赋值
  6. Samba服务全攻略
  7. 教你遇事最有水平的处理方法
  8. 云环境下大规模分布式计算数据感知的调度系统
  9. 汇总少了退款汇总 多了一笔支付汇总 很可能是因为商户退款配置的是正交易权限(配置的问题)
  10. MVC如何分离Controller与View在不同的项目?
  11. NFS客户端在/etc/fstab设置开机挂载后,开机时无法进入系统
  12. LabVIEW学习笔记(1)
  13. 利用NoteExpress统一Elsevier旗下期刊参考文献格式
  14. SharePoint Designer 2010 简介 - SharePoint Designer - Office.com
  15. 计算机动画电影英语翻译,“动画电影”英语怎么说
  16. 启发:vs运行时提示:应用程序无法正常启动(oxc000007b)。请单击确定关闭应用程序
  17. CSS的浮动属性,附架构师必备技术详解
  18. linux安装tomcat
  19. 图像处理职位面试题汇总(1)
  20. MyEclipse 2013优化技巧

热门文章

  1. java演练 猜奇偶小游戏开发 DB游戏必输的设计
  2. linux-facl权限控制-移除-复制
  3. css-animaton-随堂-风车动画-加载动画-走路动画
  4. 智能合约从入门到精通:Solidity Assembly
  5. 用electron写桌面应用
  6. C#并行编程-并发集合
  7. ansible callbacks
  8. hdu 1625(floyd判环)
  9. 业务逻辑数据层SqlDataSourcesql的输入参数
  10. Eclipse中JBOSS5.1无法启动的问题解决办法