本文整理汇总了C++中NValue::createStringFromDecimal方法的典型用法代码示例。如果您正苦于以下问题:C++ NValue::createStringFromDecimal方法的具体用法?C++ NValue::createStringFromDecimal怎么用?C++ NValue::createStringFromDecimal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NValue
的用法示例。
在下文中一共展示了NValue::createStringFromDecimal方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: opDivideDecimals
NValue NValue::opDivideDecimals(const NValue lhs, const NValue rhs) const {
if ((lhs.getValueType() != VALUE_TYPE_DECIMAL) ||
(rhs.getValueType() != VALUE_TYPE_DECIMAL))
{
throw SQLException(SQLException::dynamic_sql_error, "No decimal NValue in decimal subtract");
}
if (lhs.isNull() || rhs.isNull()) {
TTInt retval;
retval.SetMin();
return getDecimalValue( retval );
}
TTLInt calc;
calc.FromInt(lhs.getDecimal());
calc *= NValue::kMaxScaleFactor;
if (calc.Div(rhs.getDecimal())) {
char message[4096];
snprintf( message, 4096, "Attempted to divide %s by %s causing overflow/underflow (or divide by zero)",
lhs.createStringFromDecimal().c_str(), rhs.createStringFromDecimal().c_str());
throw SQLException(SQLException::data_exception_numeric_value_out_of_range,
message);
}
TTInt retval;
if (retval.FromInt(calc) || retval > NValue::s_maxDecimal || retval < s_minDecimal) {
char message[4096];
snprintf( message, 4096, "Attempted to divide %s by %s causing overflow. Unscaled result was %s",
lhs.createStringFromDecimal().c_str(), rhs.createStringFromDecimal().c_str(),
calc.ToString(10).c_str());
throw SQLException(SQLException::data_exception_numeric_value_out_of_range,
message);
}
return getDecimalValue(retval);
}
示例2: peekDecimalString
// exists for test.
static inline std::string peekDecimalString(const NValue value) {
return value.createStringFromDecimal();
}
示例3: opMultiplyDecimals
/*
* Avoid scaling both sides if possible. E.g, don't turn dec * 2 into
* (dec * 2*kMaxScale*E-12). Then the result of simple multiplication
* is a*b*E-24 and have to further multiply to get back to the assumed
* E-12, which can overflow unnecessarily at the middle step.
*/
NValue NValue::opMultiplyDecimals(const NValue &lhs, const NValue &rhs) const {
if ((lhs.getValueType() != VALUE_TYPE_DECIMAL) &&
(rhs.getValueType() != VALUE_TYPE_DECIMAL))
{
throw SQLException(SQLException::dynamic_sql_error, "Non-decimal NValue in decimal multiply");
}
if (lhs.isNull() || rhs.isNull()) {
TTInt retval;
retval.SetMin();
return getDecimalValue( retval );
}
if ((lhs.getValueType() == VALUE_TYPE_DECIMAL) &&
(rhs.getValueType() == VALUE_TYPE_DECIMAL))
{
TTLInt calc;
calc.FromInt(lhs.getDecimal());
calc *= rhs.getDecimal();
calc /= NValue::kMaxScaleFactor;
TTInt retval;
if (retval.FromInt(calc) || retval > NValue::s_maxDecimal || retval < s_minDecimal) {
char message[4096];
snprintf(message, 4096, "Attempted to multiply %s by %s causing overflow/underflow. Unscaled result was %s",
lhs.createStringFromDecimal().c_str(), rhs.createStringFromDecimal().c_str(),
calc.ToString(10).c_str());
throw SQLException(SQLException::data_exception_numeric_value_out_of_range,
message);
}
return getDecimalValue(retval);
} else if (lhs.getValueType() != VALUE_TYPE_DECIMAL)
{
TTLInt calc;
calc.FromInt(rhs.getDecimal());
calc *= lhs.castAsDecimalAndGetValue();
calc /= NValue::kMaxScaleFactor;
TTInt retval;
retval.FromInt(calc);
if (retval.FromInt(calc) || retval > NValue::s_maxDecimal || retval < s_minDecimal) {
char message[4096];
snprintf(message, 4096, "Attempted to multiply %s by %s causing overflow/underflow. Unscaled result was %s",
lhs.createStringFromDecimal().c_str(), rhs.createStringFromDecimal().c_str(),
calc.ToString(10).c_str());
throw SQLException(SQLException::data_exception_numeric_value_out_of_range,
message);
}
return getDecimalValue(retval);
}
else
{
TTLInt calc;
calc.FromInt(lhs.getDecimal());
calc *= rhs.castAsDecimalAndGetValue();
calc /= NValue::kMaxScaleFactor;
TTInt retval;
retval.FromInt(calc);
if (retval.FromInt(calc) || retval > NValue::s_maxDecimal || retval < s_minDecimal) {
char message[4096];
snprintf(message, 4096, "Attempted to multiply %s by %s causing overflow/underflow. Unscaled result was %s",
lhs.createStringFromDecimal().c_str(), rhs.createStringFromDecimal().c_str(),
calc.ToString(10).c_str());
throw SQLException(SQLException::data_exception_numeric_value_out_of_range,
message);
}
return getDecimalValue(retval);
}
}