简体   繁体   English

将浮点双精度转换为非浮点字符串

[英]Convert Floating point double to non floating point string

I have the following number: 我有以下电话号码:

1.0645208E10 , which is in my case a double value. 1.0645208E10 ,在我1.0645208E10 ,这是一个双1.0645208E10值。 I would like to convert it into 106.45 . 我想将其转换为106.45

Any recommendation how to get 106.45 ? 任何建议如何获得106.45

I appreciate your answers! 感谢您的回答!

You can try this: 您可以尝试以下方法:

    double bigDouble = 1.0645208E10;
    String strDouble = String.format(Locale.ENGLISH, "%.2f", bigDouble/100000000);
    System.out.println(strDouble);

It will give you 106.45 它会给你106.45

But be aware of the fact that the output has nothing to do with the original value!! 但是请注意,输出与原始值无关! Is one hundred million times smaller... 小一亿倍...

Any recommendation how to get 106.45? 任何建议如何获得106.45?

If you want to get only output then you can do following. 如果只想输出,则可以执行以下操作。

Double d = 1.0645208E10;
String s = d.toString().replace(".", "");//Converts into string and removes dot (.)
String s1 = s.substring(0, 5);//it gets only first 5 characters 
String s2 = s1.substring(0, 3) + "." + s1.substring(3, 5);//it adds decimal point after first 3 character
System.out.println("Expected Output: " + s2);

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

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