Closed leongwaikay closed 7 years ago
This PR was deployed a couple of days back and solves point 1. https://github.com/Coursemology/coursemology2/pull/2448 It's not retroactive so you'll have to update existing packages to see the benefit.
The double rounding off is from the str()
method. We can change it to to_string
if you prefer.
Doesn't matter which method is used, just avoid rounding off. I did some Googling and it seems to suggest that to_string is useful, but you might want to do your own research on this.
http://en.cppreference.com/w/cpp/string/basic_string/to_string suggests it could be misleading for small numbers and yield unexpected results for floating point types.
Is that ok for you?
Converts a floating point value to a string with the same content as what
std::sprintf(buf, "%f", value)
would produce for sufficiently large buf.
Actually this is what we want because in C we use printf("%f", value)
to display the value.
I get this output on my compiler
23.430000
0.000000
10000000000000000000000000000000000000000.000000
0.000000
123456789.000000
The only weird output is 10e40 for to_string
. Can we actually use sprintf
?
Actually I think this might affect C++ code yah? I suppose we can use sprintf
in the append to override custom_evaluator to fix the display.
If you want the equivalent of printf("%f", value)
then we shouldn't remove trailing zeroes at all so it'll match what the students see on their own machines.
We can change to to_string
so you don't need to override custom_evaluator
.
Come to think of it, yea maybe we don't need to remove the trailing zeroes since printf
truncates to 6dp. My concern is that when we move to teaching C++, their cout
output might appear different.
Currently there are 2 issues:
2.0
, it only displays2
float
anddouble
types.Proposed fix. double types should be displayed in full precision. C11 has
std::to_string
which does that. However, some string manipulation has to be done to remove trailing zeros while maintaining at least 1 dp.If for display purpose the number is too long, perhaps truncate and append ... and on mouse hover show the full number.