hello,
is there a quick solution to convert a double value to char* ?
my dll takes a double array from a vba interface and i must use a method which takes these values as a char * array. as i manage only the middle i must find a solution to do the convertion.
i've some code but i'm afraid it to be long and when i go out from DoubletoChar lnRes is null.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void main( void )
{
double lnDouble = -3.1415926535;
char * lsRes = NULL;
int lnRep = 0;
lnRep = DoubleToChar(lnDouble, lsRes);
printf("resultat : %s\n", lsRes);
}
int DoubleToChar(double pnDouble, char *psBuffer) {
int lnDecimal = 0;
int lnSign = 0;
int lnI = 0;
psBuffer = _fcvt(pnDouble, 15, &lnDecimal, &lnSign );
for (lnI = strlen(psBuffer); lnI >= lnDecimal; lnI--) {
psBuffer[lnI + 1] = psBuffer[lnI];
if (lnI == lnDecimal)
psBuffer[lnI] = '.';
}
if (lnSign == 1) {
for (lnI = strlen(psBuffer); lnI >= 0; lnI--) {
psBuffer[lnI + 1] = psBuffer[lnI];
if (lnI == 0)
psBuffer[lnI] = '-';
}
}
return 1;
}
what can i do to have the good value in lnRes and to go faster(i may have to convert an array of 1000 values one by one)
Start Free Trial