Java字符串默认_Java默认编号为字符串行为

我的eclipse工作区中有两个项目,它们有类似的任务.这两个项目都有一个特殊的部分,我将double转换为String.

我通过调用String.valueOf(var)来完成这两个项目.

在较旧的项目中,我总是以“-0.00097656”的格式获得数字,这是我需要的格式.在较新的一个中,我获得了第十个指数格式,如“-9.765625E-4”.我还有一个事实,即旧项目将字符串剪得足够小.

我的问题是:哪些命令可能导致java更改默认转换输出的行为.我已经搜索了代码,但我没有看到这样做的东西.或者它可能是一个日食选项?

我想让新项目与旧项目保持一致,我不希望每次都在新项目中使用这些字符串格式调用.旧项目中的任何地方都必须有设置或一些电话……

希望有人可以暗示一下.

最佳答案:

它在javadoc中有清楚的解释(见Double.toString()) – 格式取决于数字的大小:

If m is greater than or equal to 10-3 but less than 107, then it is represented as the integer part of m, in decimal form with no leading zeroes, followed by ‘.’ (‘\u002E’), followed by one or more decimal digits representing the fractional part of m.

If m is less than 10-3 or greater than or equal to 107, then it is represented in so-called “computerized scientific notation.” Let n be the unique integer such that 10n <= m < 10n+1; then let a be the mathematically exact quotient of m and 10n so that 1 <= a < 10. The magnitude is then represented as the integer part of a, as a single decimal digit, followed by ‘.’ (‘\u002E’), followed by decimal digits representing the fractional part of a, followed by the letter ‘E’ (‘\u0045’), followed by a representation of n as a decimal integer, as produced by the method Integer.toString(int).

如果您需要特定格式,请使用String.format()或类似内容.

标签:java,format,double,string

来源: https://codeday.me/bug/20190515/1109420.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值