Java划分为双倍和浮动,没有E [英] Java division for double and float without E

查看:188
本文介绍了Java划分为双倍和浮动,没有E的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一些大数量的分割(long / long to double,int / int来浮动)..但是当结果包含E时,我碰到了一个问题。我知道我们可以在显示时使用NumberFormat进行格式化,但这不是什么。只需要将分割的结果不涉及E,即将其四舍五入到适合该空间的最接近的float / double。 / p>

任何人都有想法?

解决方案

浮点的内部表示号码没有E存在切换(检查IEEE-754)。所以你的浮点数/双数只是数字(不是带有E或不带数字的数字)。



只有你打印出这个值才能得到E的地方。而Java使用号码打印机进行打印,所以我不明白为什么你不想在这里使用它。

  System.out.println(new DecimalFormat(#。#####)。format(doubleValue)); 


I'm doing some large number divisions (long/long to double, and int/int to float).. But I bump, to a problem when the results include the "E". I know we can use NumberFormat to format when displaying, but that's not what I. Just want the result of the divisions to not involve the "E", i.e. just round it up to the closest float/double that fits in the space.

Anybody got an idea?

解决方案

The internal representation of floating point number does not have a switch for E presence or not (check IEEE-754). So your float/double number is just number (not a number with E or without it).

The only place where you get E is when you print this value out. And while Java uses number formater for printing, so I don't see a point why you don't want to use it here.

System.out.println(new DecimalFormat("#.#####").format(doubleValue)); 

这篇关于Java划分为双倍和浮动,没有E的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆