Corretta setdec nel caso di reali senza decimali
git-svn-id: svn://10.65.10.50/trunk@712 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
eb9ed8599b
commit
d7aec9b15e
162
include/cfiles.c
162
include/cfiles.c
@ -524,92 +524,90 @@ Se si utilizza spiegarne dettagliatamente il motivo.
|
|||||||
int dec; /* numero di decimali che deve avere il numero */
|
int dec; /* numero di decimali che deve avere il numero */
|
||||||
|
|
||||||
{
|
{
|
||||||
char *s1;
|
char *s1;
|
||||||
int i, l, carry;
|
int i, l, carry;
|
||||||
|
|
||||||
if (LENGTH(s) == 0) strcpy(s, "0");
|
if (LENGTH(s) == 0) strcpy(s, "0");
|
||||||
if ((s1 = strchr(s, ',')) != NULL) *s1 = '.';
|
if ((s1 = strchr(s, ',')) != NULL) *s1 = '.';
|
||||||
s1 = strchr(s, '.');
|
s1 = strchr(s, '.');
|
||||||
if ((dec) && (s1 == NULL))
|
if ((dec) && (s1 == NULL))
|
||||||
|
{
|
||||||
|
strcat(s, ".");
|
||||||
|
s1 = strchr(s, '.');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if (!dec)
|
||||||
|
{
|
||||||
|
if (s1 == NULL) return ;
|
||||||
|
l = LENGTH(s1); /* occhio verificare */
|
||||||
|
carry = (s1[1] >= '5');
|
||||||
|
*s1 = '\0';
|
||||||
|
while (carry)
|
||||||
|
{
|
||||||
|
s1--;
|
||||||
|
if (*s1 == '-') break;
|
||||||
|
if (*s1 == '9')
|
||||||
{
|
{
|
||||||
strcat(s, ".");
|
*s1 = '0';
|
||||||
s1 = strchr(s, '.');
|
if (s == s1) break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (!dec)
|
{
|
||||||
{
|
(*s1)++;
|
||||||
l = LENGTH(s1); /* occhio verificare */
|
carry = FALSE;
|
||||||
if (s1 != NULL)
|
|
||||||
{
|
|
||||||
carry = (s1[1] >= '5');
|
|
||||||
*s1 = '\0';
|
|
||||||
while (carry)
|
|
||||||
{
|
|
||||||
s1--;
|
|
||||||
if (*s1 == '-') break;
|
|
||||||
if (*s1 == '9')
|
|
||||||
{
|
|
||||||
*s1 = '0';
|
|
||||||
if (s == s1) break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
(*s1)++;
|
|
||||||
carry = FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (carry)
|
|
||||||
{
|
|
||||||
for (i = l; i > (*s1 == '-'); i--) s[i] = s[i - 1];
|
|
||||||
s[(*s1 == '-')] = '1';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
s1++;
|
|
||||||
l = LENGTH(s1);
|
|
||||||
if (l > dec)
|
|
||||||
{
|
|
||||||
carry = (s1[dec] >= '5');
|
|
||||||
s1[dec] = '\0';
|
|
||||||
while (carry)
|
|
||||||
{
|
|
||||||
dec--;
|
|
||||||
if (s1[dec] == '9')
|
|
||||||
{
|
|
||||||
s1[dec] = '0';
|
|
||||||
if (!dec) break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
s1[dec]++;
|
|
||||||
carry = FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
s1--;
|
|
||||||
while (carry)
|
|
||||||
{
|
|
||||||
s1--;
|
|
||||||
if (*s1 == '-') break;
|
|
||||||
if (*s1 == '9')
|
|
||||||
{
|
|
||||||
*s1 = '0';
|
|
||||||
if (s == s1) break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
(*s1)++;
|
|
||||||
carry = FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (carry)
|
|
||||||
{
|
|
||||||
for (i = l; i > (*s1 == '-'); i--) s[i] = s[i - 1];
|
|
||||||
s[(*s1 == '-')] = '1';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
while (l++ < dec) strcat(s1, "0");
|
if (carry)
|
||||||
|
{
|
||||||
|
for (i = l; i > (*s1 == '-'); i--) s[i] = s[i - 1];
|
||||||
|
s[(*s1 == '-')] = '1';
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
s1++;
|
||||||
|
l = LENGTH(s1);
|
||||||
|
if (l > dec)
|
||||||
|
{
|
||||||
|
carry = (s1[dec] >= '5');
|
||||||
|
s1[dec] = '\0';
|
||||||
|
while (carry)
|
||||||
|
{
|
||||||
|
dec--;
|
||||||
|
if (s1[dec] == '9')
|
||||||
|
{
|
||||||
|
s1[dec] = '0';
|
||||||
|
if (!dec) break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
s1[dec]++;
|
||||||
|
carry = FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s1--;
|
||||||
|
while (carry)
|
||||||
|
{
|
||||||
|
s1--;
|
||||||
|
if (*s1 == '-') break;
|
||||||
|
if (*s1 == '9')
|
||||||
|
{
|
||||||
|
*s1 = '0';
|
||||||
|
if (s == s1) break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
(*s1)++;
|
||||||
|
carry = FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (carry)
|
||||||
|
{
|
||||||
|
for (i = l; i > (*s1 == '-'); i--) s[i] = s[i - 1];
|
||||||
|
s[(*s1 == '-')] = '1';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
while (l++ < dec) strcat(s1, "0");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user