X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=device%2Flib%2Fprintf_large.c;h=ba43fd546cb52ccbf93a8765cf46e7d3c0b022e5;hb=4feac4f3a6ef7546d9e8f67441d36fdf940bb03f;hp=e087f64d95f3873336d00b01c3ddda5fda90ba5d;hpb=b21f90fcfcda291d97c4fda8295df83dcde6f730;p=fw%2Fsdcc diff --git a/device/lib/printf_large.c b/device/lib/printf_large.c index e087f64d..ba43fd54 100644 --- a/device/lib/printf_large.c +++ b/device/lib/printf_large.c @@ -165,7 +165,7 @@ static int output_float (float f, unsigned char reqWidth, BOOL left, BOOL zero, BOOL sign, BOOL space) #endif { - char negative=0; + BOOL negative=0; unsigned long integerPart; float decimalPart; char fpBuffer[128]; @@ -229,14 +229,19 @@ static int output_float (float f, unsigned char reqWidth, // fill buffer with the decimalPart (in normal order) fpBD=fpBI; - if (i=reqDecimals /* that's an assignment */) { - do { + + for (i=reqDecimals; i>1; i--) { decimalPart *= 10.0; // truncate the float integerPart=decimalPart; fpBuffer[fpBD++]='0' + integerPart; decimalPart-=integerPart; - } while (--i); + } + if (i) { + decimalPart *= 10.0; + // truncate the float + integerPart = decimalPart + 0.5; + fpBuffer[fpBD++] = '0' + integerPart; } minWidth=fpBI; // we need at least these