// Convert 912545 to "$9,125.45" // // (Assuming a Factor of 100, Decimal Power of 2, Currency Symbol of "$", // separator of "," and decimal point of ".") // bool OTAssetContract::FormatAmount(const OTAmount & theInput, std::string & str_output) const // Convert 545 to $5.45. { int64_t lValue = static_cast<int64_t>(theInput.GetAmount()); // -------------------------------------------------------- int32_t nFactor = atoi(m_strCurrencyFactor.Get()); // default is 100 (100 cents in a dollar) if (nFactor < 1) nFactor = 1; OT_ASSERT(nFactor > 0); // should be 1, 10, 100, etc. // -------------------------------------------------------- int32_t nPower = atoi(m_strCurrencyDecimalPower.Get()); // default is 2. ($5.05 is moved 2 decimal places.) if (nPower < 0) nPower = 0; OT_ASSERT(nPower >= 0); // should be 0, 1, 2, etc. // -------------------------------------------------------- // Lookup separator and decimal point symbols based on locale. // -------------------------------------------------------- // Get a moneypunct facet from the global ("C") locale // // NOTE: Turns out moneypunct kind of sucks. // As a result, for internationalization purposes, // these values have to be set here before compilation. // static OTString strSeparator (OT_THOUSANDS_SEP); static OTString strDecimalPoint (OT_DECIMAL_POINT); // -------------------------------------------------------- // NOTE: from web searching, I've determined that locale / moneypunct has // internationalization problems. Therefore it looks like if you want to // build OT for various languages / regions, you're just going to have to // edit stdafx.h and change the OT_THOUSANDS_SEP and OT_DECIMAL_POINT variables. // // The best improvement I can think on that is to check locale and then use // it to choose from our own list of hardcoded values. Todo. // static bool bFirstTime = true; // // -------------------------------------------------------- // if (bFirstTime) // { // bFirstTime = false; // // TODO: Add ability to customize locale here, if necessary. // const std::moneypunct<char, false> &mp = std::use_facet< std::moneypunct<char, false> >(std::locale ()); // <===== // strSeparator. Format("%c", ('\0' == mp.thousands_sep ()) ? ',' : mp.thousands_sep ()); // strDecimalPoint.Format("%c", ('\0' == mp.decimal_point ()) ? '.' : mp.decimal_point ()); // } // -------------------------------------------------------- str_output = OTAssetContract::formatLongAmount(lValue, nFactor, nPower, m_strCurrencySymbol.Get(), strSeparator.Get(), strDecimalPoint.Get()); return true; }
// Convert 912545 to "$9,125.45" // // (Assuming a Factor of 100, Decimal Power of 2, Currency Symbol of "$", // separator of "," and decimal point of ".") // bool OTAssetContract::FormatAmount(const OTAmount & theInput, std::string & str_output) const // Convert 545 to $5.45. { long lValue = static_cast<long>(theInput.GetAmount()); // -------------------------------------------------------- int nFactor = atoi(m_strCurrencyFactor.Get()); // default is 100 (100 cents in a dollar) if (nFactor < 1) nFactor = 1; // OT_ASSERT(nFactor > 0); // should be 1, 10, 100, etc. // -------------------------------------------------------- int nPower = atoi(m_strCurrencyDecimalPower.Get()); // default is 2. ($5.05 is moved 2 decimal places.) if (nPower < 0) nPower = 0; // OT_ASSERT(nPower >= 0); // should be 0, 1, 2, etc. // -------------------------------------------------------- // Lookup separator and decimal point symbols based on locale. // -------------------------------------------------------- // Get a moneypunct facet from the global ("C") locale // static OTString strSeparator (","); static OTString strDecimalPoint ("."); // -------------------------------------------------------- static bool bFirstTime = true; // -------------------------------------------------------- if (bFirstTime) { bFirstTime = false; // TODO: Add ability to customize locale here, if necessary. const std::moneypunct<char, false> &mp = std::use_facet< std::moneypunct<char, false> >(std::locale ()); // <===== strSeparator. Format("%c", ('\0' == mp.thousands_sep ()) ? ',' : mp.thousands_sep ()); strDecimalPoint.Format("%c", ('\0' == mp.decimal_point ()) ? '.' : mp.decimal_point ()); } // -------------------------------------------------------- str_output = OTAssetContract::formatLongAmount(lValue, nFactor, nPower, m_strCurrencySymbol.Get(), strSeparator.Get(), strDecimalPoint.Get()); return true; }
OTAmount::OTAmount(const OTAmount & other) : m_lAmount(other.GetAmount()) { }