java - 将 double 转换为 int 返回 0 而不是 1 为什么?
问题描述
答案是 0 而不是 1,为什么?
public class Student {
public static void main(String[] args) {
double s=1.3901863961920014E-5;
int a= (int)s;
System.out.println("a: "+a);
}
}
解决方案
因为你的号码
1.3901863961920014E-5
是 :
0.000013901863961920014013868597546608185666627832688391208648681640625
您可以尝试像这样检查全长:
double s = 1.3901863961920014E-5;
BigDecimal b = new BigDecimal(s);
System.out.println(b);
=> 0.000013901863961920014013868597546608185666627832688391208648681640625
推荐阅读
- swift - 为什么我不能从这个 https 请求中收到价值?
- ruby-on-rails - ActionMailer 发出的 SMTP 请求是什么样的?
- ruby - 何时使用关键字参数和选项哈希?
- ruby - 如何创建函数 .find_by_label(x),相当于 .find_by(label: x)?
- java - Junit 测试缺少的测试
- google-cloud-platform - Hive 到 GCP BigQuery 同步
- reactjs - 子组件中的 ondragend 事件调用父组件方法
- jquery - jQuery 更改淡出时间加载器屏幕
- css - 使用伪 :after-element 创建三角形颜色叠加
- kubernetes - K8s 服务无法ping通