fix
This commit is contained in:
parent
bb46f5218c
commit
a1032b168c
1 changed files with 18 additions and 15 deletions
|
@ -46,6 +46,7 @@ cvt(value, ndigit, decpt, sign, ecvtflag)
|
||||||
if (ndigit < 0) ndigit = 0;
|
if (ndigit < 0) ndigit = 0;
|
||||||
if (ndigit > NDIGITS) ndigit = NDIGITS;
|
if (ndigit > NDIGITS) ndigit = NDIGITS;
|
||||||
pe = &buf[ndigit];
|
pe = &buf[ndigit];
|
||||||
|
buf[0] = '\0';
|
||||||
|
|
||||||
*sign = 0;
|
*sign = 0;
|
||||||
if (value < 0) {
|
if (value < 0) {
|
||||||
|
@ -83,24 +84,26 @@ cvt(value, ndigit, decpt, sign, ecvtflag)
|
||||||
*p++ = (int)value + '0';
|
*p++ = (int)value + '0';
|
||||||
value = 10.0 * (value - (int)value);
|
value = 10.0 * (value - (int)value);
|
||||||
}
|
}
|
||||||
p = pe;
|
if (pe >= buf) {
|
||||||
*p += 5; /* round of at the end */
|
p = pe;
|
||||||
while (*p > '9') {
|
*p += 5; /* round of at the end */
|
||||||
*p = '0';
|
while (*p > '9') {
|
||||||
if (p > buf) ++*--p;
|
*p = '0';
|
||||||
else {
|
if (p > buf) ++*--p;
|
||||||
*p = '1';
|
else {
|
||||||
++*decpt;
|
*p = '1';
|
||||||
if (! ecvtflag) {
|
++*decpt;
|
||||||
/* maybe add another digit at the end,
|
if (! ecvtflag) {
|
||||||
because the point was shifted right
|
/* maybe add another digit at the end,
|
||||||
*/
|
because the point was shifted right
|
||||||
if (pe > buf) *pe = '0';
|
*/
|
||||||
pe++;
|
if (pe > buf) *pe = '0';
|
||||||
|
pe++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*pe = '\0';
|
||||||
}
|
}
|
||||||
*pe = '\0';
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue