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

网站收录 作用官方网站建设流程

网站收录 作用,官方网站建设流程,怀化网站优化联系方式,永康网站推广1 java的允许函数的默认参数吗?java不支持类似C那样#xff0c;为函数设定默认参数#xff0c;所以需要做的事情是#xff0c;自己用函数重载的方式进行模拟。如下public class FFOverload {public String getName(String givenName,String familyName){return givenName那样为函数设定默认参数所以需要做的事情是自己用函数重载的方式进行模拟。如下public class FFOverload {public String getName(String givenName,String familyName){return givenName.familyName;}public String getName(String givenName){return getName(givenName,BBB);}public static void main(String[] args) {FFOverload demoDefaultParanew FFOverload();System.out.println(demoDefaultPara.getName(AAA));System.out.println(demoDefaultPara.getName(AAA, CCC));}}输出:AAA.BBBAAA.CCC2.  为什么floating point number不准确首先来验证一下public class FloatTest {public static void main(String[] args) {float a 1.01f; //dont forget the trailing f , else it will be treated as a double.float b 1.002f;float c 1.0000009f;float d a b c;System.out.println(expected: 3.0120009, actua: d);}}输出expected: 3.0120009, actua: 3.012001然后来看看原因:In most programming languages, floating point numbers are represented a lot like scientific notation:with an exponent anda mantissa (also called the significand).A very simple number, say 9.2, is actually this fraction:5179139571476070 * 2 -49Where the exponent is -49 and the mantissa is 5179139571476070.The reason it is impossible to represent some decimal numbers this way is that both the exponent and the mantissa must be integers. In other words, all floats must be an integer multiplied by an integer power of 2.Floating point numbers only have 32 or 64 bits of precision, so the digits are cut off at some point, and the resulting number is 0.199999999999999996 in decimal, not 0.2.3. 如何尽可能准确地表示Floating Point Numbers?3.1 使用BigDecimal Classbut currently there is a small unsolved issue in the code below. I did not see the difference between HALF_UP and HALF_DOWN in the code below.import java.math.*;public class FFBigDecimal {public static void main(String[] args) {BigDecimal bigDecimal1 new BigDecimal(1.001);BigDecimal bigDecimal2 new BigDecimal(1.0005);BigDecimal bigDecimal3 new BigDecimal(1.000007);BigDecimal bigDecimaBase new BigDecimal(2.52150);BigDecimal bigDecimal4 bigDecimaBase.setScale(3, RoundingMode.HALF_DOWN);System.out.println(Big Decimal is bigDecimal4.toString());BigDecimal bigDecimal5 bigDecimaBase .setScale(3, RoundingMode.HALF_UP);System.out.println(Big Decimal is bigDecimal5.toString());}}输出Big Decimal is 2.521Big Decimal is 2.522why????  I expected:2.5212.522HALF_UP的定义是这样的“Rounding mode to round towards nearest neighbor unless both neighbors are equidistant, in which case round up. Behaves as for RoundingMode.UP if the discarded fraction is ≥ 0.5; otherwise, behaves as for RoundingMode.DOWN. Note that this is the rounding mode commonly taught at school.”后来终于知道了原因算是比较坑爹了。BigDecimal的构造函数需要用String作为参数否则将会出现一些比较奇怪的结果。所以上面的程度如果修改为:import java.math.*;public class FFBigDecimal {public static void main(String[] args) {BigDecimal bigDecimal1 new BigDecimal(1.001);BigDecimal bigDecimal2 new BigDecimal(1.0005);BigDecimal bigDecimal3 new BigDecimal(1.000007);//test 1//bigDeciimal3 is immutable, so// WRONG: bigDecimal3.add(bigDecimal1).add(bigDecimal2);// CORRECT: bigDecimal3 bigDecimal3.add(bigDecimal1).add(bigDecimal2);bigDecimal3 bigDecimal3.add(bigDecimal1).add(bigDecimal2);BigDecimal bigDecimaBase new BigDecimal(2.52150);BigDecimal bigDecimal4 bigDecimaBase.setScale(3, RoundingMode.HALF_DOWN);System.out.println(Big Decimal is bigDecimal4.toString());BigDecimal bigDecimal5 bigDecimaBase .setScale(3, RoundingMode.HALF_UP);System.out.println(Big Decimal is bigDecimal5.toString());}}就是符合预期的得到的输出结果将是:Big Decimal is 2.521Big Decimal is 2.5223.2 如果在Double和Float中二选一选择Double.Double (8 位)Float (4 位)
http://www.yutouwan.com/news/423852/

相关文章:

  • 龙岗建设企业网站郑州经济技术开发区教师招聘公告
  • 阿里云加WordPress建站旅游网站国际业务怎样做
  • 长春网站推广公司手机端网站html好看的模板
  • 做网站小图片分类有免费建站的网站吗
  • 深圳建立网站营销搜索引擎入口yandex
  • 小企业网站建设费用一年我赢网seo优化网站
  • 越南的网站建设网站建设公司推荐5788
  • 软件培训网站管理公司网站一般做什么
  • 长白山开发建设集团网站小程序代理招商公司
  • 广州建网站哪家最好手机网银怎么开通
  • 如何绑定网站域名宁波建筑公司排名
  • 婚纱摄影网站制作设计房子的软件免费
  • 安徽龙山建设有限公司网站网站首页设计创意
  • 学校网站首页设计怎样创造网站
  • 去年做那些网站能致富单位做网站怎么做
  • 信誉好的邢台做网站石家庄市住房和城乡建设局官方网站
  • 平台网站建设合同上海最好网站建设公司
  • 怎么更改网站名称我的网站为什么
  • 广州市提取住房补贴建设银行网站福州小程序开发公司
  • 如何做社团网站邯郸网站制
  • 潍坊 企业网站建设西安分类信息网站
  • 网站制作报价开网址是什么
  • 网站建设合同怎么交印花税做商城网站在哪里注册营业执照
  • 个人dw网页设计seo综合查询接口
  • 综合门户类网站有哪些张店易宝网站建设
  • 广州做网站哪个公司做得好汕尾网站建设公司
  • 做网站成功的企业如何让网站长尾关键词有排名
  • 手机网站建设代码昆明seo
  • 东莞高端模板建站e福州怎么代缴医保
  • 中山小榄网站线上营销平台