program memory usage need help

Status
Not open for further replies.
Yes, 302.
signed long (3.023452) = 3
accuracy = 2
k = 10*10 = 100
302 - 300 = 2
So, the value after the pointer will be 02.
 

it is 2 or 02 ? it is 2 i think. So we are losing 0 before 2 and seeing wrong value.
 

No, take a look at changes:
Code:
while (Accuracy--)
        {
              if (Accuracy>=Len2) String[Len++] = '0';
              else String[Len++] = AftDot[i++];
        }
This will add '0' when it needed.
 

ty.
still have problem.

between zero and minus one.

-0.625 still it is showing 0.625 not giving the sign. after minus one like -1.235 it is ok.

- - - Updated - - -

No, take a look at changes:
Code:
while (Accuracy--)
        {
              if (Accuracy>=Len2) String[Len++] = '0';
              else String[Len++] = AftDot[i++];
        }
This will add '0' when it needed.

ty.
still have problem.

between zero and minus one.

-0.625 still it is showing 0.625 not giving the sign. after minus one like -1.235 it is ok.
 

Damn, how about now? :lol:
Code:
void FloatToString (float Value, char * String, char Accuracy)
{
        signed long k = 1;
        signed long tmp;
        char Len, Len2, i=0;
        char AftDot[6];
        for (tmp = Accuracy; tmp; tmp--)  k *= 10;
        tmp = MOD(((signed long)Value)*k - Value*k);
        if (Value<0) 
        {
         *String++ = '-';
         sLongToStr((int)(-Value), String);
        }
        else
        LongToStr((int)(-Value), String);
        Len = StringLen(String);
        String[Len++]='.';
        sLongToStr(tmp, AftDot);
        Len2 =  StringLen(AftDot);

        while (Accuracy--)
        {
              if (Accuracy>=Len2) String[Len++] = '0';
              else String[Len++] = AftDot[i++];
        }
}
 


after plus 1 it is showing minus, like -1.115 nbut i have make some corrections. i think you overlooked the errors.


LongToStr((int)(-Value), String); this line corrected like this. sLongToStr((int)(Value), String);


and ty again. you are so helpfull.
 
Last edited:

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…