-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataOut.c
61 lines (57 loc) · 1.87 KB
/
dataOut.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <xc.h>
//March 23, 2019
extern int i;
extern int status;
char *formatString (double value, int behindTheDecimalNumbers, char * additionalCharacters)
{
// char *buffer;
// static char BBUuff[10];
// buffer = &BBUuff[0];
int length;
char *Obuffer;
static char OHbuffer[256];
// status = 0;
// for (int a = 0; a < 10; a++)
// OHbuffer[a] = 0;
Obuffer = &OHbuffer[0];
// unsigned char *decimalPoint;
// char decPt = '.';
if((value > 1000.0) || (value < -1000.0)) {
while(1)
SLEEP(1);
}
if(behindTheDecimalNumbers == 0)
length = sprintf(OHbuffer,"%+.0f",value);
else if(behindTheDecimalNumbers == 1)
length = sprintf(OHbuffer, "%+.1f",value);
else if(behindTheDecimalNumbers == 2)
length = sprintf(OHbuffer, "%+.2f",value); // ftoa((float)(value),&status);
else if (behindTheDecimalNumbers == 3)
length = sprintf(OHbuffer, "%+.3f",value);
else if (behindTheDecimalNumbers == 3)
length = sprintf(OHbuffer, "%+.4f",value);
else if (behindTheDecimalNumbers == 3)
length = sprintf(OHbuffer, "%+.5f",value);
else if (behindTheDecimalNumbers == 3)
length = sprintf(OHbuffer, "%+.6f",value);
else
length = sprintf(OHbuffer, "%+f",value);
// if( value > 0)
// *Obuffer++ = ' ';
// memcpy(Obuffer,buffer, (size_t) 10);
// decimalPoint = strchr(Obuffer,decPt);
// decimalPoint++;
// for ( i =0; i < behindTheDecimalNumbers; i++)
// decimalPoint++;
// while(*additionalCharacters != 0)
// *decimalPoint++ = *additionalCharacters++;
// *decimalPoint = '\0';
while(*additionalCharacters != 0)
OHbuffer[length++] = *additionalCharacters++;
OHbuffer[length] = 0;
return Obuffer;
}