Hi,
is there any way to format numbers in sfml, for example with the thousand separator?
In the following example the number is formatted correctly in the console but how to implement it into sfml? Could not find any solution for it so far.
I guess this line is wrong/incomplete?:
numbertext.setString(toString<unsigned long long>(var));
Thx in advance for any help.
#include <SFML/Graphics.hpp>
#include <string>
#include <sstream>
#include <locale>
#include <iostream>
template <typename T>
std::string toString(T arg)
{
std::stringstream ss;
ss << arg;
return ss.str();
}
int main()
{
sf::RenderWindow mMainWindow(sf::VideoMode(500, 500), "Window");
mMainWindow.setFramerateLimit(40);
#ifdef _WIN32
std::locale loc("English_America");
#else
std::locale loc("en_US.UTF8");
#endif
unsigned long long var = 100000000;
sf::Font myFont;
myFont.loadFromFile("Arial.ttf");
sf::Text numbertext(toString<unsigned long long>(var), myFont);
while (mMainWindow.isOpen())
{
sf::Event event;
bool click = false;
sf::Vector2i mousePos;
while (mMainWindow.pollEvent(event))
{
switch (event.type)
{
case sf::Event::Closed:
mMainWindow.close();
break;
case sf::Event::MouseButtonPressed:
if (event.mouseButton.button == sf::Mouse::Left)
{
click = true;
mousePos = sf::Vector2i (event.mouseButton.x, event.mouseButton.y);
break;
}
}
}
if(click)
{
var = var *1.5;
std::cout.imbue(loc);
std::cout << std::fixed << var << '\n';
numbertext.setString(toString<unsigned long long>(var));
}
mMainWindow.clear();
mMainWindow.draw(numbertext);
mMainWindow.display();
}
return 0;
}