File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -75,8 +75,13 @@ std::string floating_point_to_java_string(float_type value)
75
75
std::ostringstream raw_stream;
76
76
raw_stream << value;
77
77
const auto raw_decimal = raw_stream.str ();
78
- if (raw_decimal.find (' .' ) == std::string::npos)
78
+ const bool is_scientific = raw_decimal.find (' e' ) != std::string::npos;
79
+ if (
80
+ raw_decimal.find (' .' ) == std::string::npos &&
81
+ !is_scientific) // don't add trailing .0 if in scientific notation
82
+ {
79
83
return raw_decimal + " .0" ;
84
+ }
80
85
return raw_decimal;
81
86
}();
82
87
const bool is_lossless = [&] {
Original file line number Diff line number Diff line change @@ -129,4 +129,10 @@ TEST_CASE(
129
129
REQUIRE (floating_point_to_java_string (-5.56268e-309 ) == " -5.56268e-309" );
130
130
#endif
131
131
}
132
+
133
+ SECTION (" Precise exponent" )
134
+ {
135
+ REQUIRE (floating_point_to_java_string (3e+06 ) == " 3e+06" );
136
+ REQUIRE (floating_point_to_java_string (3e+06f ) == " 3e+06f" );
137
+ }
132
138
}
You can’t perform that action at this time.
0 commit comments