Код
void main(void)
{
float minSet1 = 0.5;
unsigned char Setting[11] = " ";
NumbConverter(Setting, minSet1, 36);
}
void NumbConverter (void* destination, float numb, unsigned char numbDecimal)
{
unsigned char* array = (unsigned char*)destination;
unsigned int whole;
unsigned long decimal;
whole = numb; // целая часть
switch (numbDecimal)
{
case 36:
decimal = (numb - whole) * 1000000; // дробная часть
sprintf((char*)array, (const far rom char*)"%03d.%06u", whole, decimal);
break;
case 43:
decimal = (numb - whole) * 1000; // дробная часть
sprintf((char*)array, (const far rom char*)"%04d.%03u", whole, decimal);
break;
case 46:
decimal = (numb - whole) * 1000000; // дробная часть
sprintf((char*)array, (const far rom char*)"%04d.%06u", whole, decimal);
break;
}
}
{
float minSet1 = 0.5;
unsigned char Setting[11] = " ";
NumbConverter(Setting, minSet1, 36);
}
void NumbConverter (void* destination, float numb, unsigned char numbDecimal)
{
unsigned char* array = (unsigned char*)destination;
unsigned int whole;
unsigned long decimal;
whole = numb; // целая часть
switch (numbDecimal)
{
case 36:
decimal = (numb - whole) * 1000000; // дробная часть
sprintf((char*)array, (const far rom char*)"%03d.%06u", whole, decimal);
break;
case 43:
decimal = (numb - whole) * 1000; // дробная часть
sprintf((char*)array, (const far rom char*)"%04d.%03u", whole, decimal);
break;
case 46:
decimal = (numb - whole) * 1000000; // дробная часть
sprintf((char*)array, (const far rom char*)"%04d.%06u", whole, decimal);
break;
}
}
На выходе я получаю массив Setting с содержимым "000.000007" вместо "000.500000". Не знаю, как быть