请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
器件型号:TMS320F28379D 您好,专家,
我想将 float32变量截断为其小数点后的2个位、目前我正在执行以下操作、可否让我知道有没有更好的方法、 我想避免任何除法运算。
#include <math.h> //Round to 2 decimal places //Option 1: float32_t currentMechTheta = 0.3278; currentMechTheta = floorf(pMotor->ptrFCL->qep.MechTheta * 100) / 100; //0.3200 //Option 2: float32_t currentMechTheta = 0.3278; currentMechTheta = roundf(pMotor->ptrFCL->qep.MechTheta * 100) / 100; //0.3300