#include <stdio.h>
#include <stdint.h>
static char table[]={'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
void num2char(char *str, double number, uint8_t g, uint8_t l)
{
uint8_t i;
int temp = number/1;
double t2 = 0.0;
for (i = 1; i<=g; i++)
{
if (temp==0)
str[g-i] = table[0];
else
str[g-i] = table[temp%10];
temp = temp/10;
}
*(str+g) = '.';
temp = 0;
t2 = number;
for(i=1; i<=l; i++)
{
temp = t2*10;
str[g+i] = table[temp%10];
t2 = t2*10;
}
*(str+g+l+1) = '\0';
}
int main(int argc, char const *argv[])
{
char str[20];
num2char(str, 23.56821312, 8, 10);
printf("%s\n", str);
return 0;
}
测试结果
00000023.5682131
其实有更简单的方法 将其打印出来的
int x = object.roi.x;
int y = object.roi.y + object.roi.height;
string label = format("%f", object.peakvalue);
int baseLine;
Size labelSize = getTextSize(label, FONT_HERSHEY_SIMPLEX, 0.5, 1, &baseLine);
putText(frame2, label, cv::Point(x, y), FONT_HERSHEY_SIMPLEX, 0.75, Scalar(0, 255, 0), 2);