STTNet
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 宏定义 
静态 Public 成员函数 | 所有成员列表
stt::data::PrecisionUtil类 参考

负责浮点数精度处理 更多...

#include <sttnet.h>

静态 Public 成员函数

static std::string & getPreciesFloat (const float &number, const int &bit, std::string &str)
 将浮点数格式化为指定小数位数的字符串表示。 更多...
 
static float & getPreciesFloat (float &number, const int &bit)
 将 float 数值保留指定位数的小数,并直接修改原值。 更多...
 
static std::string & getPreciesDouble (const double &number, const int &bit, std::string &str)
 将双精度浮点数格式化为指定小数位数的字符串表示。 更多...
 
static double & getPreciesDouble (double &number, const int &bit)
 将 double 数值保留指定位数的小数,并直接修改原值。 更多...
 
static float & getValidFloat (float &number, const int &bit)
 根据数值动态调整小数精度,保留指定数量的有效数字。 更多...
 

详细描述

负责浮点数精度处理

成员函数说明

static std::string& stt::data::PrecisionUtil::getPreciesDouble ( const double &  number,
const int &  bit,
std::string &  str 
)
static

将双精度浮点数格式化为指定小数位数的字符串表示。

参数
number输入的 double 数值。
bit保留的小数位数。
str用于存储格式化后的字符串。
返回
格式化结果字符串的引用。
static double& stt::data::PrecisionUtil::getPreciesDouble ( double &  number,
const int &  bit 
)
static

将 double 数值保留指定位数的小数,并直接修改原值。

参数
number待处理的 double 变量(将被修改)。
bit保留的小数位数。
返回
修改后的 double 引用。
static std::string& stt::data::PrecisionUtil::getPreciesFloat ( const float &  number,
const int &  bit,
std::string &  str 
)
static

将浮点数格式化为指定小数位数的字符串表示。

参数
number输入的浮点数。
bit保留的小数位数。
str用于存储格式化后的字符串。
返回
格式化结果字符串的引用。
static float& stt::data::PrecisionUtil::getPreciesFloat ( float &  number,
const int &  bit 
)
static

将 float 数值保留指定位数的小数,并直接修改原值。

参数
number待处理的 float 变量(将被修改)。
bit保留的小数位数。
返回
修改后的 float 引用。
static float& stt::data::PrecisionUtil::getValidFloat ( float &  number,
const int &  bit 
)
static

根据数值动态调整小数精度,保留指定数量的有效数字。

对于小于 1 的小数,会先确定其最前位有效数字所处的位置, 然后在此基础上保留 bit 位有效数字。 修改后的数值将四舍五入保留合适的小数位,并写回原变量。

参数
number待处理的 float 数值(将被修改)。
bit希望保留的有效数字位数。
返回
修改后的 float 引用。

该类的文档由以下文件生成: