如何使用Java打印没有科学符号的双重值? [英] How to print double value without scientific notation using Java?

查看:111
本文介绍了如何使用Java打印没有科学符号的双重值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  double dexp = 12345678; 
System.out.println(dexp:+ dexp);

它显示这个E符号: 1.2345678E7



我想要这样打印: 12345678


$ b $

解决方案

你可以使用 printf() %f

  double dexp = 12345678; 
System.out.printf(dexp:%f\\\
,dexp);

这将打印 dexp:12345678.000000 。如果您不想使用小数部分,请使用

  System.out.printf(dexp:%.0f\\\
,dexp);

这使用文档



默认原始代码中使用的toString()格式说明 here


I want to print a double value in Java without exponential form.

double dexp = 12345678;
System.out.println("dexp: "+dexp);

It shows this E notation: 1.2345678E7.

I want it to print it like this: 12345678

What is the best way to prevent this?

解决方案

You could use printf() with %f:

double dexp = 12345678;
System.out.printf("dexp: %f\n", dexp);

This will print dexp: 12345678.000000. If you don't want the fractional part, use

System.out.printf("dexp: %.0f\n", dexp);

This uses the format specifier language explained in the documentation.

The default toString() format used in your original code is spelled out here.

这篇关于如何使用Java打印没有科学符号的双重值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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