float打印不正確

芯片:CH583

代碼

????????static?char?xxx[10]={"3.14"};
????????float?pi;
????????char?fbuf[20];
????????DBG("x?=?%s\n",xxx);
????????sscanf(xxx,"%f",&pi);
????????sprintf(fbuf,"%.2f",pi);
????????DBG("pi?=?%.2f\n",pi);
????????DBG("fbuf?=?%s\n",fbuf);
????????float?rlt?=?strtof(xxx,?NULL);
????????sprintf(fbuf,"%.2f",rlt);
????????DBG("rlt?=?%.2f\n",rlt);
????????DBG("fbuf?=?%s\n",fbuf);
????????float?fpi?=?3.14;
????????sprintf(fbuf,"%.2f",fpi);
????????DBG("fpi?=?%.2f\n",fpi);
????????DBG("fpi*100?=?%d\n",(int)(fpi*100));
????????DBG("fbuf?=?%s\n",fbuf);

DBG宏的實(shí)現(xiàn)

#define?DBG(...)?printf("?DBG(%s,?%s(),?%d):?",?__FILE__,?__FUNCTION__,?__LINE__);?printf(__VA_ARGS__)

打印結(jié)果

?DBG(../src/Main.c,?main(),?749):?x?=?3.14
?DBG(../src/Main.c,?main(),?752):?pi?=?26815622256785016688296265592222112551708132452936578279936498398813364362571671098643215977672002762693733515732368436221370366071748541264718157228015616.00
?DBG(../src/Main.c,?main(),?753):?fbuf?=?2.00
?DBG(../src/Main.c,?main(),?756):?rlt?=?26815615859885384735558591743984408416899026634245440356407978903749122491113867963109291794919019276406862025209102462237971718664841348387476629572550656.00
?DBG(../src/Main.c,?main(),?757):?fbuf?=?2.00
?DBG(../src/Main.c,?main(),?760):?fpi?=?26815615859885384735558591743984408416899026634245440356407978903749122491113867963109291794919019276406862025209102462237971718664841348387476629572550656.00
?DBG(../src/Main.c,?main(),?761):?fpi*100?=?314
?DBG(../src/Main.c,?main(),?762):?fbuf?=?2.02

c 庫(kù)選擇

image.png


熱門產(chǎn)品 : USB3.0 HUB控制器:CH634

這樣使用C庫(kù),打印%f也是不對(duì)

image.png


你好,添加數(shù)學(xué)庫(kù)和stdlib.h,這里查看打印如下:

image.png

針對(duì)你上面打印信息異常情況,可以先注意配置是否相同。將代碼發(fā)送至lpc@wch.cn,我們這邊復(fù)現(xiàn)查看。


只有登錄才能回復(fù),可以選擇微信賬號(hào)登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频