mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-26 17:36:05 -05:00
use fmtlib instead of sstream in numToString and intToHex
This commit is contained in:
parent
5645399a9f
commit
bebc7b4074
1 changed files with 7 additions and 9 deletions
|
@ -5,7 +5,6 @@
|
||||||
#include "../DefaultInclude.hpp"
|
#include "../DefaultInclude.hpp"
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <sstream>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
@ -64,9 +63,7 @@ namespace geode {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
std::string intToHex(T i) {
|
std::string intToHex(T i) {
|
||||||
std::stringstream stream;
|
return fmt::format("{:#x}", i);
|
||||||
stream << std::showbase << std::setbase(16) << (uint64_t)i;
|
|
||||||
return stream.str();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -75,15 +72,16 @@ namespace geode {
|
||||||
* @param num Number to convert to string
|
* @param num Number to convert to string
|
||||||
* @param precision Precision of the converted number
|
* @param precision Precision of the converted number
|
||||||
* @returns Number as string
|
* @returns Number as string
|
||||||
|
* @note Precision has no effect on integers
|
||||||
*/
|
*/
|
||||||
template <class Num>
|
template <class Num>
|
||||||
std::string numToString(Num num, size_t precision = 0) {
|
std::string numToString(Num num, size_t precision = 0) {
|
||||||
std::stringstream ss;
|
if constexpr (std::is_floating_point_v<Num>) {
|
||||||
if (precision) {
|
if (precision) {
|
||||||
ss << std::fixed << std::setprecision(precision);
|
return fmt::format("{:.{}f}", num, precision);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ss << num;
|
return fmt::to_string(num);
|
||||||
return ss.str();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue