Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
void float_to_ASCII_with_2_decimal_v5(float fx, char *pt)
{
unsigned long e = 0; // 0 to more than 65535.
unsigned long d = 0; // 0 to more than 65535.
float f0, chiffre_decimal=0.0;
int k=0;
if (fx < 0)
{
*(pt) = '-'; // 0cx2D
chiffre_decimal=-fx;
}
else
{
*(pt) = '+'; // 0x2B signe +
chiffre_decimal=fx;
}
e =(unsigned long) floor(chiffre_decimal); // Partie entière.
d =(chiffre_decimal - (float)e) * 100; // Partie décimale (2 chiffres);
// Partie entière de 99999 à 0 :
if (e/100000L >= 0) *(pt+1) =(unsigned char) (e/100000L) + 0x30;
e = e%100000L;
if (e/10000L >= 0) *(pt+2) =(unsigned char) (e/10000L) + 0x30;
e = e%10000L...
What a pity the OP didn't see my comments about the use of floating point and signle precision in my Post #2.what you see is the resolution problem of a single precision floating point variable.
2^23 = 8,388,608
Bonjour Susan,If you don't want to use the MikroC library functions then a quick Google (other search engines are available!) of 'ltoa c' and 'ftoa c' produce a number of examples.
(I'm in Melbourne - as you say, a lovely place but 0C this morning as we are in the middle of winter; promises to be a sunny day but cool!)
Susan
while(1) // Endless loop.
{
unsigned char *pointeur_de_char; // Déclaration d'un pointeur (*) de char "pointeur_de_char".
// En n'indiquant aucun chiffre entre les cochets [], le compilateur ajustera automatiquement la taille du
// tableau, et allouera en mémoire RAM, le bon nombre d'éléménts, soit 13 ...
char txt[13];
- 9999999,00
- 9899999,00
- 9799999,00
- 9699999,00
- 9599999,00
- 9499999,00
- 9399999,00
- 9299999,00
- 9199999,00
- 9099999,00
- 8999999,00
- 8899999,00
- 8799999,00
- 8699999,00
- 8599999,00
- 8499999,00
- 8399999,00
- 8299999,00
- 8199999,00
- 8099999,00
- 7999999,00
- 7899999,00
- 7799999,00
- 7699999,00
- 7599999,00
- 7499999,00
- 7399999,00
- 7299999,00
- 7199999,00
- 7099999,00
- 6999999,00
- 6899999,00
- 6799999,00
- 6699999,00
- 6599999,00
- 6499999,00
- 6399999,00
- 6299999,00
- 6199999,00
- 6099999,00
- 5999999,00
- 5899999,00
- 5799999,00
- 5699999,00
- 5599999,00
- 5499999,00
- 5399999,00
- 5299999,00
- 5199999,00
- 5099999,00
- 4999999,00
- 4899999,00
- 4799999,00
- 4699999,00
- 4599999,00
- 4499999,00
- 4399999,00
- 4299999,00
- 4199999,00
- 4099999,00
- 3999999,00
- 3899999,00
- 3799999,00
- 3699999,00
- 3599999,00
- 3499999,00
- 3399999,00
- 3299999,00
- 3199999,00
- 3099999,00
- 2999999,00
- 2899999,00
- 2799999,00
- 2699999,00
- 2599999,00
- 2499999,00
- 2399999,00
- 2299999,00
- 2199999,00
- 2099999,00
- 1999999,00
- 1899999,00
- 1799999,00
- 1699999,00
- 1599999,00
- 1499999,00
- 1399999,00
- 1299999,00
- 1199999,00
- 1099999,00
- 999999,00
- 899999,00
- 799999,00
- 699999,00
- 599999,00
- 499999,00
- 399999,00
- 299999,00
- 199999,00
- 99999,00
1,00
100001,00
200001,00
300001,00
400001,00
500001,00
600001,00
700001,00
800001,00
900001,00
1000001,00
1100001,00
1200001,00
1300001,00
1400001,00
1500001,00
1600001,00
1700001,00
1800001,00
1900001,00
2000001,00
2100001,00
2200001,00
2300001,00
2400001,00
2500001,00
2600001,00
2700001,00
2800001,00
2900001,00
3000001,00
3100001,00
3200001,00
3300001,00
3400001,00
3500001,00
3600001,00
3700001,00
3800001,00
3900001,00
4000001,00
4100001,00
4200001,00
4300001,00
4400001,00
4500001,00
4600001,00
4700001,00
4800001,00
4900001,00
5000001,00
5100001,00
5200001,00
5300001,00
5400001,00
5500001,00
5600001,00
5700001,00
5800001,00
5900001,00
6000001,00
6100001,00
6200001,00
6300001,00
6400001,00
6500001,00
6600001,00
6700001,00
6800001,00
6900001,00
7000001,00
7100001,00
7200001,00
7300001,00
7400001,00
7500001,00
7600001,00
7700001,00
7800001,00
7900001,00
8000001,00
8100001,00
8200001,00
8300001,00
8400001,00
8500001,00
8600001,00
8700001,00
8800001,00
8900001,00
9000001,00
9100001,00
9200001,00
9300001,00
9400001,00
9500001,00
9600001,00
9700001,00
9800001,00
9900001,00
Merci !Hello,
works fine on my 18F26K22 and UART output ...
Test Toggle Led Rouge RA4
Test float_to_ASCII_with_2_decimal_v7(f1,pt) gamme -9 999 999 à + 9 999 999;
Valeur de depart = - 9999999,00 Increment = 10000.01;
but in your code
Code:while(1) // Endless loop. { unsigned char *pointeur_de_char; // Déclaration d'un pointeur (*) de char "pointeur_de_char". // En n'indiquant aucun chiffre entre les cochets [], le compilateur ajustera automatiquement la taille du // tableau, et allouera en mémoire RAM, le bon nombre d'éléménts, soit 13 ... char txt[13];
try to put declarations outside of the main
as global variables..
16F887 has less RAM and ROM than 18F ...
check in compile messages if you get an
.....IRP_Bit ...... => Bank problems
Result on terminal
Hello,Hi,
adding/subtracting 100,000 to 9,999,999 may work.
But does adding/subtracting 0.1 to 9,999,999 also work? I´m not sure.
The problem I see is the 24 bit mantisse limit of a singleprecision floating point variable.
Klaus
- 0,05
- 0,04
- 0,03
- 0,02
- 0,01
- 0,00
+ 0,00
+ 0,01
+ 0,02
+ 0,03
+ 0,04
+ 0,05
+ 0,06
+ 0,07
+ 0,08
+ 0,09
+ 0,10
+ 0,11