Hi,
I am using CCS v6.1.0.00104 and TivaWare_C_Series-2.1.1.71 on EK-TM4C1294XL on Windiws 8 64 bit.
I am trying to convert float to string and want to add in to JSON string.
I am passing float as argument to the function, but in the function this float reads as -1.
If I redeclare the value or I define float as global variable and than its working fine.
Following is the code snippet.
uint32_t convertFloat2JSON(float fVal)
{
int32_t i32Idx = 0;
if(fVal<1.0 && fVal>-1.0){
i32Idx = 1;
}
uint32_t uVal = (uint32_t) (fVal*powf(10.0, 3));
UARTprintf("\nuVal:%d!!!!!",uVal);
int iSize = ftostr(uVal);
int i32Size=0;
for(i32Size = iSize-1; i32Idx <= iSize; i32Idx++){
UARTprintf(":%d",i32Idx);
uint32_t iFPow = (uint32_t) powf(10, i32Size);
uint32_t iVal = uVal / iFPow;
UARTprintf(":%d*", iVal, iVal);
uVal = uVal % iFPow;
i32Size--;
}
return (1);
}
int ftostr(uint32_t fVal)
{
// Extract integer part
uint32_t ipart = (uint32_t)fVal;
if(ipart == 0) return 1;
int i = 0;
while(ipart){
i++;
ipart = ipart/10;
}
return i;
}
Can you please let me know what is the problem in this?
Thanks,
Bhavesh