简体   繁体   English

将浮点转换为字符串

[英]Converting Floating Point to String

I'm pretty new to Java and I am currently working on a project where I need to work with Floating points . 我对Java刚起步,目前正在从事一个需要处理浮点数的项目。

I am trying to convert the value from 3.5E8 (Double value) to a string value of 350000000. I have looked on the internet but currently I can't find a solution. 我正在尝试将值从3.5E8(双精度值)转换为350000000的字符串值。我在互联网上看过,但目前找不到解决方案。

采用:

new BigDecimal(yourValue).toPlainString();

try String.format 试试String.format

String str = String.format("%.0f",3.5E8);

or 要么

String str = new DecimalFormat("#.#").format(3.5E8);

You can use the BigDecimal class , toPlainString() method : 您可以使用BigDecimaltoPlainString()方法:

Returns a string representation of this BigDecimal without an exponent field. 返回此BigDecimal的字符串表示形式,不包含指数字段。

 System.out.println(new BigDecimal(doubleValue).toPlainString());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM