0
Follow
2
View

Is there a method in java to format very long numbers like this "1.551121004×10^25"?

dadawfj 注册会员
2023-01-26 06:36

Java's java.text.DecimalFormat#DecimalFormat(java.lang.String) is a useful method to format numbers, you can do like this:

        BigInteger    bigInteger    = new BigInteger("1222222222");
        DecimalFormat decimalFormat = new DecimalFormat("0.##E0");
        String        formatStr     = decimalFormat.format(bigInteger);
        System.out.println(formatStr);

For this case, the result is 1.22E9, whether I'm not sure this satisfy your demand.

And maybe you can change the format code 0.##E0 to make the result like 1.551121004×10^25

About the Author

Question Info

Publish Time
2023-01-26 06:36
Update Time
2023-01-26 06:36

Related Question

Node JS, Promise.all()检查null?

无法找到promise模块的声明文件

arcgis模型构建器密码忘了怎么办

Doris新增字段再插入问题

无法在windows10 /Visual Studio 2022上构建增强

关于#python#的问题:代码变灰,报错“code is unreachable(代码不能被运行到)“

Redis Pub Sub直接与前端使用,不使用websocket,

在iis设置完成项目的反向代理后打开网页后台出现502.3问题

Visual Studio 2022 MAC Quickview智能感知停止工作

Firebase .listUsers()不是函数