Fix NSString formatting precision problem with float

This commit is contained in:
Airy ANDRE 2012-06-08 15:45:06 +02:00
parent 633ec92b9b
commit ad5724750e

View File

@ -256,6 +256,8 @@ static inline void appendFloat(NSStringBuffer *buffer,double value,
// So let's do it our own way // So let's do it our own way
integral = trunc(value); integral = trunc(value);
fractional = roundDouble(power * (value - integral)) / power;; fractional = roundDouble(power * (value - integral)) / power;;
// Add some epsilon smaller than the precision to fix rounding problems
fractional+= pow(10., -precision-2);
if (fractional >= 1.) { if (fractional >= 1.) {
// Rounding to next integral // Rounding to next integral
integral++; integral++;