当前位置: 首页 > news >正文

建设网站号码wordpress 安装502

建设网站号码,wordpress 安装502,外包服务美剧,代码实现wordpress百度地图当我看到其他人编写不必要的Java代码并且由于缺乏对已经提供所需功能的JDK类的了解而编写了不必要的Java代码时#xff0c;我会想到很多次。 这样的一个例子是时间相关的常量的使用硬编码值的写入#xff0c;如60 #xff0c; 24 #xff0c; 1440 #xff0c;和86400时TI… 当我看到其他人编写不必要的Java代码并且由于缺乏对已经提供所需功能的JDK类的了解而编写了不必要的Java代码时我会想到很多次。 这样的一个例子是时间相关的常量的使用硬编码值的写入如60 24 1440 和86400时TIMEUNIT提供了更好的标准化的方法。 在这篇文章中我看一看一个类的示例该示例提供了开发人员经常在其上实现的功能 NumberFormat 。 NumberFormat类是java.text包的一部分该包还包括常用的DateFormat和SimpleDateFormat类。 NumberFormat是一个抽象类没有公共构造函数其后代的实例是通过具有诸如getInstance getCurrencyInstanceInstance和getPercentInstance之类的重载静态方法获得的。 货币 下一个代码清单演示了如何调用NumberFormat.getCurrencyInstanceLocale以获取NumberFormat的实例该实例以货币友好格式显示数字。 演示NumberFormat的货币支持 /*** Demonstrate use of a Currency Instance of NumberFormat.*/ public void demonstrateCurrency() {writeHeaderToStandardOutput(Currency NumberFormat Examples);final NumberFormat currencyFormat NumberFormat.getCurrencyInstance(Locale.US);out.println(15.5 - currencyFormat.format(15.5));out.println(15.54 - currencyFormat.format(15.54));out.println(15.345 - currencyFormat.format(15.345)); // rounds to two decimal placesprintCurrencyDetails(currencyFormat.getCurrency()); }/*** Print out details of provided instance of Currency.** param currency Instance of Currency from which details* will be written to standard output.*/ public void printCurrencyDetails(final Currency currency) {out.println(Concurrency: currency);out.println(\tISO 4217 Currency Code: currency.getCurrencyCode());out.println(\tISO 4217 Numeric Code: currency.getNumericCode());out.println(\tCurrency Display Name: currency.getDisplayName(Locale.US));out.println(\tCurrency Symbol: currency.getSymbol(Locale.US));out.println(\tCurrency Default Fraction Digits: currency.getDefaultFractionDigits()); } 执行以上代码后结果如下所示 Currency NumberFormat Examples15.5 - $15.50 15.54 - $15.54 15.345 - $15.35 Concurrency: USDISO 4217 Currency Code: USDISO 4217 Numeric Code: 840Currency Display Name: US DollarCurrency Symbol: $Currency Default Fraction Digits: 2 上面的代码和相关的输出表明用于货币的NumberFormat实例实际上是DecimalFormat 会根据语言环境自动应用适当的位数和适当的货币符号。 百分比 下一个代码清单和相关的输出演示了NumberFormat使用以百分比友好格式显示数字。 演示NumberFormat的百分比格式 /*** Demonstrate use of a Percent Instance of NumberFormat.*/ public void demonstratePercentage() {writeHeaderToStandardOutput(Percentage NumberFormat Examples);final NumberFormat percentageFormat NumberFormat.getPercentInstance(Locale.US);out.println(Instance of: percentageFormat.getClass().getCanonicalName());out.println(1 - percentageFormat.format(1));// will be 0 because truncated to Integer by Integer divisionout.println(75/100 - percentageFormat.format(75/100));out.println(.75 - percentageFormat.format(.75));out.println(75.0/100 - percentageFormat.format(75.0/100));// will be 0 because truncated to Integer by Integer divisionout.println(83/93 - percentageFormat.format((83/93)));out.println(93/83 - percentageFormat.format(93/83));out.println(.5 - percentageFormat.format(.5));out.println(.912 - percentageFormat.format(.912));out.println(---- Setting Minimum Fraction Digits to 1:);percentageFormat.setMinimumFractionDigits(1);out.println(1 - percentageFormat.format(1));out.println(.75 - percentageFormat.format(.75));out.println(75.0/100 - percentageFormat.format(75.0/100));out.println(.912 - percentageFormat.format(.912)); }Percentage NumberFormat Examples1 - 100% 75/100 - 0% .75 - 75% 75.0/100 - 75% 83/93 - 0% 93/83 - 100% .5 - 50% .912 - 91% ---- Setting Minimum Fraction Digits to 1: 1 - 100.0% .75 - 75.0% 75.0/100 - 75.0% .912 - 91.2% 代码和百分比的输出NumberFormat使用表明通过默认的实例NumberFormat 实际上是一个DecimalFormat通过返回在这种情况下 NumberFormat.getPercentInstance区域的方法没有小数位乘所提供的数目由100假定它是如果提供的话则为百分比的十进制等效值 并添加一个百分号。 整数 接下来显示的少量代码及其相关输出演示了NumberFormat使用以整数格式显示数字。 演示NumberFormat的整数格式 /*** Demonstrate use of an Integer Instance of NumberFormat.*/ public void demonstrateInteger() {writeHeaderToStandardOutput(Integer NumberFormat Examples);final NumberFormat integerFormat NumberFormat.getIntegerInstance(Locale.US);out.println(7.65 - integerFormat.format(7.65));out.println(7.5 - integerFormat.format(7.5));out.println(7.49 - integerFormat.format(7.49));out.println(-23.23 - integerFormat.format(-23.23)); }Integer NumberFormat Examples7.65 - 8 7.5 - 8 7.49 - 7 -23.23 - -23 如上面的代码和相关输出所示 NumberFormat方法getIntegerInstanceLocale返回一个实例该实例将提供的数字表示为整数。 固定位数 下一个代码清单和相关输出演示了如何使用NumberFormat打印浮点数的定点表示形式。 换句话说使用NumberFormat可以使一个数字在小数点左侧“整数”数字和小数点右侧“小数”数字的正好具有规定位数的数字表示。 演示定点数字的NumberFormat /*** Demonstrate generic NumberFormat instance with rounding mode,* maximum fraction digits, and minimum integer digits specified.*/ public void demonstrateNumberFormat() {writeHeaderToStandardOutput(NumberFormat Fixed-Point Examples);final NumberFormat numberFormat NumberFormat.getNumberInstance();numberFormat.setRoundingMode(RoundingMode.HALF_UP);numberFormat.setMaximumFractionDigits(2);numberFormat.setMinimumIntegerDigits(1);out.println(numberFormat.format(234.234567));out.println(numberFormat.format(1));out.println(numberFormat.format(.234567));out.println(numberFormat.format(.349));out.println(numberFormat.format(.3499));out.println(numberFormat.format(0.9999)); }NumberFormat Fixed-Point Examples234.23 1 0.23 0.34 0.35 1 上面的代码和相关的输出演示了对最小“整数”位数的精确控制该位数代表小数点左边至少一个因此在适用时显示为零和最大“分数”小数点右边的数字。 尽管未显示但也可以指定最大整数位数和最小分数位数。 结论 我曾经用过这篇文章来研究如何使用NumberFormat以不同的方式显示数字货币百分比整数固定的小数点等并且通常意味着无需编写或减少代码即可将数字写成数字格式。 当我第一次开始写这篇文章时我设想包括有关NumberFormat的直接后代 DecimalFormat和ChoiceFormat 的示例和讨论但是已经确定这篇文章已经足够冗长了。 我可能会在以后的博客文章中介绍NumberFormat这些后代。 翻译自: https://www.javacodegeeks.com/2014/08/java-numeric-formatting.html
http://www.pierceye.com/news/693003/

相关文章:

  • 免费域名x网站网站前期准备工作
  • 陕西网站建设公司排名智能优化网站
  • 做瞹瞹网站萍乡做网站的公司有哪些
  • 网站建设的类型有几种wordpress搜索返回页面内容
  • 建设网站备案与不备案区别招远建网站首选公司
  • 四川住房和城乡建设厅网站三类人员软文网站备案如何查询
  • 个人与企业签订网站开发合同网页制作教程实例
  • 做网站遇到竞争对手怎么办wordpress中文版邮件发送
  • 美橙互联旗下网站渐变网站
  • 做网站域名需要在哪里备案微信答题小程序
  • 购物网站页面布局个人站长做导航网站
  • wordpress 增强编辑器网站暂时关闭 seo
  • 重庆网站设计开发培训广西省住房和城乡建设厅官网
  • 购物网站模板免费下载网站排名快速提升工具
  • 中山制作网站的公司滨江区网站开发公司
  • 申请建设工作网站的函酒店网站建设方案策划方案
  • 宠物店网站模板你是网站设计有限公司的项目经理
  • 潍坊网站开发公司2018做网站还赚钱吗
  • 做化妆品网站怎样wordpress映射到外网访问
  • 关于加强门户网站建设爱客crm客户管理系统
  • 网站备案的是域名还是空间电子商务网站建设携程
  • 建设企业网站管理系统目的开发一个网站的费用
  • 网站开发和浏览器兼容问题软文广告案例分析
  • 更新网站的方法自贡网站建设哪家好
  • 沈阳网络建网站个人电子商务网站建设的总体目标
  • asp 大型网站开发优化公司治理结构
  • 做外贸 建网站要注意什么ssr网站怎么做
  • 杭州做兼职网站建设老五wordpress
  • 网站建设工资怎么样网站曝光率
  • 亚泰国际建设股份有限公司网站app推广方案模板