예제 #1
0
/**
 * Serialize sign and value using radix point (no exponent).
 */
std::string NValue::createStringFromDecimal() const {
    assert(!isNull());
    std::ostringstream buffer;
    TTInt scaledValue = getDecimal();
    if (scaledValue.IsSign()) {
        buffer << '-';
    }
    TTInt whole(scaledValue);
    TTInt fractional(scaledValue);
    whole /= NValue::kMaxScaleFactor;
    fractional %= NValue::kMaxScaleFactor;
    if (whole.IsSign()) {
        whole.ChangeSign();
    }
    buffer << whole.ToString(10);
    buffer << '.';
    if (fractional.IsSign()) {
        fractional.ChangeSign();
    }
    std::string fractionalString = fractional.ToString(10);
    for (int ii = static_cast<int>(fractionalString.size()); ii < NValue::kMaxDecScale; ii++) {
        buffer << '0';
    }
    buffer << fractionalString;
    return buffer.str();
}
예제 #2
0
파일: decimal.cpp 프로젝트: cs-wang/CLAIMS
string Decimal::toString(unsigned number_of_fractinal_digits) const {
  if (isNull()) return "NULL";
  string ress = "";
  TTInt rest = this->word[0];
  rest.ToString(ress);
  int sign = 0;
  if (rest.IsSign()) sign = 1;
  while ((Decimal::kMaxDecScale + sign - (int) ress.length()) >= 0)
    ress.insert(sign, "0");
  if(number_of_fractinal_digits > 0)
    ress.insert(ress.length() - Decimal::kMaxDecScale, ".");
  ress.erase(ress.size() - Decimal::kMaxDecScale + number_of_fractinal_digits,
             Decimal::kMaxDecScale - number_of_fractinal_digits);
  return ress;
}