floatToStr truncates instead on rounding giving incorrect last digit in 50% of cases
Original Reporter info from Mantis: tiger
-
Reporter name:
Original Reporter info from Mantis: tiger
- Reporter name:
Description:
floatToStr does not produce the mathematical 'precision' it claims, instead it truncates the string representation of the data to that number of digits without doing the correct rounding first.
1/24 = 0.0416666666666666666666666666666666666666666...
thus the correct finite precision is a number ending a 7.
Function should round to required number of digits before converting to a string. Precision relates to a number not to a series of characters in a string.
Steps to reproduce:
begin
rtmp:=1/24.0;
// FloatToStrF(rtmp,ffGeneral,Precision,3)
writeln(FloatToStrF(rtmp,ffGeneral,8,4));
EXIT;
end.
0.0416666
Additional information:
http://www.freepascal.org/docs-html/rtl/sysutils/floattostrf.html
Description
FloatToStrF converts the floating point number value to a string representation, according to the settings of the parameters Format, Precision and Digits.
So compiler is not conforming to spec.
Mantis conversion info:
- Mantis ID: 21169
- OS: linux
- Platform: PC
- Version: 2.4.0
- Fixed in version: 2.6.0