castToString(const float& value); from example project and nlohmann::json
I've used the example project to serialize my data containing (amongst other stuff) some floats. After looking at the result I found that I had to write those floats with precision to just one decimal since my data doesn't require more and thus I could make files smaller.
std::string castToString(const float& value)
{
return float_to_string_one_decimal(value);
}
This little function casts our float to string with required formatting using sprintf_s:
sprintf_s(c, BUFFER_SIZE, "%.1f", f);
But funny stuff, when I didn't get desired result and put a breakpoint in it I found that it was never called :)
Then I did same with std::string castToString(const std::string& value); and it was completely OK.
Looks like when it gets to the floats in my structures it uses nlohmann's caster instead of those we provide in "StringCast.h".
This is what my data looks like:
struct MeteoData
{
std::unordered_map<std::string, Town> m_towns;
}
struct Town
{
std::string shortName;
std::string longName;
std::vector<MeteoRecord> records;
};
struct MeteoRecord
{
Date date;
float tempMin;
float tempMean;
float tempMax;
float precip;
};
struct Date
{
uint16_t year;
uint8_t month;
uint8_t day;
};
Of course, I used the example code without proper understanding of how it works, but I'm working on it :)
Hello. Sorry for not responding so long. I'll take a look at the problem soon.