unsigned char number[20] = {0};
float sum_float = 0;
sum_float = 1524.45;
UARTSend(uart0_id, "float = ", 8);
sprintf((char *)number,"%.2f",sum_float);
UARTSend(uart0_id, number, 20);
sprintf函数转换其他的都正常,但是转换浮点数时出现的结果是0.00,这是为什么啊?
后面我自己写了一个sprintf的,
case 'f':
UARTSend(uart0_id, "in float", 8);
float_num = (float)va_arg(ap, double);
int_num = (int)float_num;
UARTSend(uart0_id, (unsigned char*)&int_num, 2);
bias = float_num - int_num;
va_arg(ap, double);的结果页是0,请教为什么?
|