10#ifndef COMMON_PERCENT_HPP
11#define COMMON_PERCENT_HPP
42 Percent(
double value,
bool is_percent =
true);
43 Percent(
int value,
bool is_percent =
false);
76 template <
typename T =
double>
103inline Percent::Percent(
double value,
bool is_percent) : value(value), is_percent(is_percent) {}
115inline Percent::Percent(
int value,
bool is_percent) : value(value), is_percent(is_percent) {}
171 return this->value + value;
191 return this->value - value;
211 return this->value * value;
231 return this->value / value;
251 value += this->value;
271 value -= this->value;
291 value *= this->value;
311 value /= this->value;
331 if (percent.is_percent)
332 return value + percent.value;
333 return percent.value;
352 if (percent.is_percent)
353 return value - percent.value;
354 return percent.value;
373 if (percent.is_percent)
374 return value * percent.value;
375 return percent.value;
394 if (percent.is_percent)
395 return value / percent.value;
396 return percent.value;
428 return std::move(
Sprintf(
Sprintf(
"%%.%df%%%%", precision).c_str(), value * 100));
430 return std::move(
Sprintf(
Sprintf(
"%%.%df", precision).c_str(), value));
447 this->is_percent = is_percent;
466 this->is_percent = is_percent;
friend T operator+(const T &value, const Percent &percent)
百分比类重载加法运算符
T & SubtractPercent(T &value) const
实现百分比类的百分比减法
T & DividePercent(T &value) const
实现百分比类的百分比除法
friend T operator*(const T &value, const Percent &percent)
百分比类重载乘法运算符
std::string Percentage(uint precision=2) const
获取百分数字符串
friend std::ostream & operator<<(std::ostream &out, const Percent &percent)
百分比类重载输出流运算符
T & AddPercent(T &value) const
实现百分比类的百分比加法
friend T operator/(const T &value, const Percent &percent)
百分比类重载除法运算符
T & MultiplyPercent(T &value) const
实现百分比类的百分比乘法
friend T operator-(const T &value, const Percent &percent)
百分比类重载减法运算符
Percent & Assign(double value, bool is_percent=true)
百分比类的赋值函数
bool IsPercent() const
判断是否是百分比
T operator*(const T &value, const Percent &percent)
百分比类重载乘法运算符
std::string Sprintf(const char *format,...)
格式化输出字符串
T operator-(const T &value, const Percent &percent)
百分比类重载减法运算符
T operator/(const T &value, const Percent &percent)
百分比类重载除法运算符
std::ostream & operator<<(std::ostream &out, const Interval &interval)
区间类重载输出流运算符
List< U > operator+(const List< U > &list1, const List< U > &list2)
列表类重载加法运算符