32using std::stringstream;
33using std::istringstream;
50 return ((d < 0.0) ? ceil(d - 0.5) : floor(d + 0.5));
59 return static_cast<int>((d < 0.0) ? ceil(d - 0.5) : floor(d + 0.5));
73 istringstream iStr(str);
76 if (!(iStr >> dDummy))
88 size_t nPos = str.find_first_not_of(
" \t");
89 if (nPos != string::npos)
90 str = str.substr(nPos);
93 if ((str[0] ==
'-') || (str[0] ==
'+'))
97 return (str.find_first_not_of(
"0123456789") == string::npos);
105 ostr.fill(args.chFill);
106 ostr.width(args.nWidth);
114string strDbl(
double const dX,
int const nDigits)
118 ss.precision(nDigits);
126string strDblRight(
double const dX,
int const nDigits,
int const nWidth,
bool const bShowDash)
129 ss << fixed << right;
142 ss.precision(nDigits);
156 ss << fixed << right;
170 stringstream ss, spaces;
171 int nPadding = nWidth -
static_cast<int>(strIn.size());
173 for (
int i = 0; i < nPadding / 2; ++i)
176 ss << spaces.str() << strIn << spaces.str();
178 if (nPadding > 0 && nPadding % 2 != 0)
189 stringstream ss, spaces;
190 int nPadding = nWidth -
static_cast<int>(strIn.size());
192 for (
int i = 0; i < nPadding / 2; ++i)
195 ss << spaces.str() << strIn << spaces.str();
197 if (nPadding > 0 && nPadding % 2 != 0)
206string strRight(
const string& strIn,
int const nWidth)
208 stringstream ss, spaces;
209 int nPadding = nWidth -
static_cast<int>(strIn.size()) - 1;
210 for (
int i = 0; i < nPadding; ++i)
212 ss << spaces.str() << strIn;
220string strRight(
const char* pchIn,
int const nWidth)
223 stringstream ss, spaces;
224 int nPadding = nWidth -
static_cast<int>(strIn.size()) - 1;
225 for (
int i = 0; i < nPadding; ++i)
227 ss << spaces.str() << strIn;
235string strLeft(
const string& strIn,
int const nWidth)
237 stringstream ss, spaces;
238 int nPadding = nWidth -
static_cast<int>(strIn.size());
239 for (
int i = 0; i < nPadding; ++i)
241 ss << strIn << spaces.str();
248string strLeft(
const char* pchIn,
int const nWidth)
251 stringstream ss, spaces;
252 int nPadding = nWidth -
static_cast<int>(strIn.size());
253 for (
int i = 0; i < nPadding; ++i)
255 ss << strIn << spaces.str();
262string strRightPerCent(
double const d1,
double const d2,
int const nWidth,
int const nDigits,
bool const bShowDash)
265 ss << fixed << right;
281 double dResult = 100 * d1 / d2;
283 stringstream ssResult;
284 ssResult << fixed << right;
285 ssResult.precision(nDigits);
286 ssResult <<
"(" << dResult <<
"%)";
288 long int nResultWidth = ssResult.str().size();
290 for (
int i = 0; i < (nWidth - nResultWidth - 1); i++)
293 ss << ssResult.str();
This file contains global definitions for CoastalME.
bool bFPIsEqual(const T d1, const T d2, const T dEpsilon)
double dRound(double const d)
Correctly rounds doubles.
bool bIsStringValidInt(string &str)
Checks to see if a string can be read as a valid integer, from https://stackoverflow....
int nRound(double const d)
Version of the above that returns an int.
string strLeft(const string &strIn, int const nWidth)
Left-aligns string within a field of given width, pads with blank spaces to enforce alignment....
string strDblRight(double const dX, int const nDigits, int const nWidth, bool const bShowDash)
Converts double to string with specified number of decimal places, within a field of given width,...
string strRightPerCent(double const d1, double const d2, int const nWidth, int const nDigits, bool const bShowDash)
Calculates a percentage from two numbers then, if the result is non-zero, right-aligns the result as ...
string strDbl(double const dX, int const nDigits)
Converts double to string with specified number of places after the decimal. From https://stackoverfl...
string strCentre(const char *pchIn, int const nWidth)
Centre-aligns char array within a field of given width, pads with blank spaces to enforce alignment....
ostream & operator<<(ostream &ostr, const FillToWidth &args)
Operator that inserts a given fill character, to a given width, into an output stream....
string strRight(const string &strIn, int const nWidth)
Right-aligns string within a field of given width, pads with blank spaces to enforce alignment....
bool bIsStringValidDouble(string &str)
Checks to see if a string can be read as a valid double number. Does not find trailing (i....
string strIntRight(int const nX, int const nWidth)
Converts int to string within a field of given width, pads with blank spaces to enforce alignment....