FloatToStrSimple for Pascal

General discussion on mikroPascal PRO for AVR.
Post Reply
Author
Message
Vit2
Posts: 77
Joined: 15 Apr 2015 10:00

FloatToStrSimple for Pascal

#1 Post by Vit2 » 11 Mar 2022 10:10

I can't convert code C to pascal from "aCkO"

Code: Select all

void FloatToStrSimple(float f, char * txt, char dec) {
   unsigned long n;
   short i = 0, j, tmp = 0, len = dec;
   unsigned long p[10] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000};

   n = f * p[dec];

   if (n < p[dec])
      tmp = 1;

   do {
      if (i == dec) {
         txt[i++] = '.';
         continue;
      }
      txt[i++] = n % 10 + '0';
      n /= 10;
   } while((len-- > 0) || n);

   if (tmp)
      txt[i++] = '0';

   txt[i] = '\0';

   for (j = i - 1, i = 0; i < j; i++, j--)
       tmp = txt[i], txt[i] = txt[j], txt[j] = tmp;
}

Vit2
Posts: 77
Joined: 15 Apr 2015 10:00

Re: FloatToStrSimple for Pascal

#2 Post by Vit2 » 24 Mar 2022 09:20

No knowers?

Post Reply

Return to “mikroPascal PRO for AVR General”