File tree Expand file tree Collapse file tree
main/java/icu/easyj/core/util
test/java/icu/easyj/core/util Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31,6 +31,9 @@ public abstract class NumberUtils {
3131 */
3232 public static String convertScientificToNormal (String scientificNumberStr ) {
3333 int indexE = scientificNumberStr .toUpperCase ().indexOf ("E" );
34+ if (indexE < 0 ) {
35+ return scientificNumberStr ;
36+ }
3437
3538 int exponential = Integer .parseInt (scientificNumberStr .substring (indexE + 1 ));
3639
@@ -65,12 +68,7 @@ public static String convertScientificToNormal(String scientificNumberStr) {
6568 }
6669
6770 public static String doubleToString (Double d ) {
68- String doubleStr = d .toString ();
69- if (doubleStr .contains ("E" )) {
70- return convertScientificToNormal (doubleStr );
71- } else {
72- return doubleStr ;
73- }
71+ return convertScientificToNormal (d .toString ());
7472 }
7573
7674}
Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ public class NumberUtilsTest {
1515 */
1616 @ Test
1717 public void test_convertScientificToNormal () {
18+ Assertions .assertEquals ("123456789" , NumberUtils .convertScientificToNormal ("123456789" ));
19+
1820 Assertions .assertEquals ("123456789" , NumberUtils .convertScientificToNormal ("1.23456789E8" ));
1921 Assertions .assertEquals ("123456789.1" , NumberUtils .convertScientificToNormal ("1.234567891E8" ));
2022 Assertions .assertEquals ("123456789.12" , NumberUtils .convertScientificToNormal ("1.2345678912E8" ));
You can’t perform that action at this time.
0 commit comments