输出精度控制

【小数位数】、【小数精度】

小数位的显示长度控制需要两步设置,其实比较简单,比如:

#include <sstream>

osgText::Text* text = dynamic_cast<osgText::Text*>(textNode->getDrawable(0));
std::wstringstream ss;
osg::Vec3d pos = _osgView->getCursorPickPoint();

//设置小数位数只保留3位,整数部分不限制
ss.setf(std::ios::fixed, std::ios::floatfield);
ss.precision(3);

ss << L"X:" << pos.x() << L", Y:"  << pos.y() << L", Z:" << pos.z() ;
text->setText(ss.str().c_str()); 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章