2023-02-18 01:14:01 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
class Percents
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Percents() = default;
|
|
|
|
|
|
|
|
explicit Percents(int value) noexcept
|
|
|
|
: raw_value_(value * 100)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
explicit Percents(float value) noexcept
|
|
|
|
: raw_value_(std::round(value * 10000))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] constexpr int to_int() const noexcept
|
|
|
|
{
|
|
|
|
return raw_value_ / 100;
|
|
|
|
}
|
|
|
|
|
2023-08-06 03:26:29 +00:00
|
|
|
[[nodiscard]] constexpr float to_fraction() const noexcept
|
|
|
|
{
|
|
|
|
return raw_value_ / 10000.F;
|
|
|
|
}
|
|
|
|
|
2023-02-18 01:14:01 +00:00
|
|
|
[[nodiscard]] std::string to_string() const;
|
|
|
|
|
|
|
|
constexpr bool operator==(Percents const& rhs) const noexcept
|
|
|
|
{
|
|
|
|
return raw_value_ == rhs.raw_value_;
|
|
|
|
}
|
|
|
|
|
|
|
|
constexpr bool operator<(Percents const& rhs) const noexcept
|
|
|
|
{
|
|
|
|
return raw_value_ < rhs.raw_value_;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int raw_value_ = 0;
|
|
|
|
};
|