Floating point 整数乘以10浮点数

Floating point 整数乘以10浮点数,floating-point,integer,arduino,Floating Point,Integer,Arduino,我有一个整数,它是一个小数点乘以10的温度。例如:235的整数应该变成23.5的浮点。我怎么把它放进浮球里 我知道我可以通过int/10和int%10得到小数点前的数字。我能把这两个值合并成一个浮点数吗?你想得有点过头了。通过将int转换为float并将其除以10,将保留小数: float degrees; int degreesTimesTen; degreesTimesTen = 235; degrees = (float)degreesTimesTen/10; // degrees i

我有一个整数,它是一个小数点乘以10的温度。例如:235的整数应该变成23.5的浮点。我怎么把它放进浮球里


我知道我可以通过int/10和int%10得到小数点前的数字。我能把这两个值合并成一个浮点数吗?

你想得有点过头了。通过将int转换为float并将其除以10,将保留小数:

float degrees;
int degreesTimesTen;

degreesTimesTen = 235;
degrees = (float)degreesTimesTen/10;

// degrees is equal to 23.5

很高兴我能帮忙!或者除以10.0,对。默认情况下,语言将看到一个整数除以一个整数,并以整数形式进行计算,因此235/10=23。但是,将任一参数更改为float将使其成为浮点除法。如果值为235,则“(浮动)值/10”或“值/10.0”都给出23.5。