我在做UCGUI时遇到这样一个问题,
void button_set_data_float(BUTTON_Handle button_in,float data_in)
{
unsigned long data1,data2;
float data3=0;
data3=4.2*100;
data1=data3;
data2=data1/100;
data1=data1-data2*100;
itoa_1(data2,datax,10,data1,0);
BUTTON_SetText(button_in,datax );
}
这样的函数运行后按键会显示4.2,这是对的。但如果修改一下:
void button_set_data_float(BUTTON_Handle button_in,float data_in)
{
unsigned long data1,data2;
float data3=0;
data_in=4.2;
data3=data_in*100;
data1=data3;
data2=data1/100;
data1=data1-data2*100;
itoa_1(data2,datax,10,data1,0);
BUTTON_SetText(button_in,datax );
}
显示的居然是4.19.这是怎么回事,感觉data3=data_in*100;好像有什么问题,最头疼的是如果data_in设为其它的数如2.3,5.65之类的,显示都对,唯独data_in=4.2不行,这是怎么回事
|