mirror of
https://github.com/darlinghq/darling-cocotron.git
synced 2024-11-30 15:30:31 +00:00
Fix NSString formatting precision problem with float
This commit is contained in:
parent
633ec92b9b
commit
ad5724750e
@ -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++;
|
||||||
|
Loading…
Reference in New Issue
Block a user