double's should now be displayed with only 1 decimal.

This commit is contained in:
Tleety
2016-03-04 02:19:13 +01:00
parent 00b5a1771c
commit 778bbd13ca
3 changed files with 14 additions and 4 deletions
+2
View File
@@ -2,6 +2,8 @@
#define AmmunitionHUDSystem_h__
#include <boost/lexical_cast.hpp>
#include <sstream>
#include <iomanip>
#include "../../Engine/Core/System.h"
#include "../../Engine/GLM.h"
+2 -2
View File
@@ -54,7 +54,7 @@
<Entity name="KD">
<Components>
<c:Text>
<Content>0</Content>
<Content>0.0</Content>
<Resource>Fonts/DroidSans.ttf,64</Resource>
<Alignment>
<Left/>
@@ -66,7 +66,7 @@
<Field>KD</Field>
</c:TextFieldReader>
<c:Transform>
<Position X="2" Y="0" Z="0"/>
<Position X="1.28572214" Y="0" Z="0"/>
<Scale X="2" Y="2" Z="2"/>
</c:Transform>
</Components>
+10 -2
View File
@@ -35,9 +35,17 @@ void TextFieldReader::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
if (field.Type == "int") {
text = boost::lexical_cast<std::string>((const int&)component[fieldName]);
} else if (field.Type == "float") {
text = boost::lexical_cast<std::string>((const float&)component[fieldName]);
std::ostringstream ss;
float f = (float)component[fieldName];
ss << std::fixed << std::setprecision(2);
ss << f;
text = ss.str();
} else if (field.Type == "double") {
text = boost::lexical_cast<std::string>((const double&)component[fieldName]);
std::ostringstream ss;
double d = (double)component[fieldName];
ss << std::fixed << std::setprecision(1);
ss << d;
text = ss.str();
} else if (field.Type == "bool") {
text = boost::lexical_cast<std::string>((const bool&)component[fieldName]);
} else if (field.Type == "string") {