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

阳江市网站建设_网站建设公司_测试上线_seo优化

网站开发费应该入什么科目,wordpress用户标签,php yaf 网站开发框架,网站开发需要用到哪些设备当我看到其他人编写不必要的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.ihoyoo.com/news/55530.html

相关文章:

  • 用c 做一个小网站怎么做怎样做个网站
  • 西安个人做网站app建设网站公司哪家好
  • 中外网站建设区别如何在手机使用wordpress
  • 多城市网站设计wordpress 顶部工具栏
  • 如何做网站seo图片制作在线生成器免费版
  • 网站建设对企业的好处有哪些医院网站建设的规划方案
  • 栾城住房和城乡建设局网站小游戏代理平台
  • 个人网站备案的好处苏州十大软件公司招聘
  • 国内vps做网站要备案吗爱站库
  • 松江做网站价格沈阳网站建设价格
  • 设计师 推荐 网站深圳网络公司接单
  • 加强和改进校园网站内容建设网上书店网网站建设
  • 中国黑色网站模板网站模板怎么建设
  • 本地网站建设多少钱乐华网络公司介绍
  • 手机网站建设怎么设计刷百度关键词排名优化
  • 网站如何制作合肥公司网站建设价格低
  • 做360网站优化北京网站建设价格低
  • 网站开发用什么语言最安全中国万网张向东
  • 网站页面设计代码写文案要看的网站
  • 房地产公司 网站建设wordpress 首页展示
  • 山东新华电脑学院学网站开发网站获取信息
  • 椒江建设网保障性阳光工程网站网站 技术支持
  • 美食网站建设策划报告17zwd一起做网站普宁
  • 给别人做网站网站优化要用什么软件
  • 网站建设的目的是什么淄博亿泰信息技术有限公司
  • 网站建设合同英文模板泰安网络信息有限公司
  • 用层还是表格做网站快郑州网络推广专员
  • 网站流量少怎么办做易购网站
  • 网站备份挖掘专业团队打造专业品质
  • 怎样创建设计公司网站易优cms怎么样