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");
90 if (nPos != string::npos)
91 str = str.substr(nPos);
94 if ((str[0] ==
'-') || (str[0] ==
'+'))
98 return (str.find_first_not_of(
"0123456789") == string::npos);
106 ostr.fill(args.chFill);
107 ostr.width(args.nWidth);
115string strDbl(
double const dX,
int const nDigits)
119 ss.precision(nDigits);
127string strDblRight(
double const dX,
int const nDigits,
int const nWidth,
bool const bShowDash)
130 ss << fixed << right;
132 ss.width(nWidth - 1);
145 ss.precision(nDigits);
159 ss << fixed << right;
161 ss.width(nWidth - 1);
173 stringstream ss, spaces;
174 int nPadding = nWidth -
static_cast<int>(strIn.size());
176 for (
int i = 0; i < nPadding / 2; ++i)
179 ss << spaces.str() << strIn << spaces.str();
181 if (nPadding > 0 && nPadding % 2 != 0)
192 stringstream ss, spaces;
193 int nPadding = nWidth -
static_cast<int>(strIn.size());
195 for (
int i = 0; i < nPadding / 2; ++i)
198 ss << spaces.str() << strIn << spaces.str();
200 if (nPadding > 0 && nPadding % 2 != 0)
209string strRight(
const string& strIn,
int const nWidth)
211 stringstream ss, spaces;
212 int nPadding = nWidth -
static_cast<int>(strIn.size()) - 1;
214 for (
int i = 0; i < nPadding; ++i)
217 ss << spaces.str() << strIn;
225string strRight(
const char* pchIn,
int const nWidth)
228 stringstream ss, spaces;
229 int nPadding = nWidth -
static_cast<int>(strIn.size()) - 1;
231 for (
int i = 0; i < nPadding; ++i)
234 ss << spaces.str() << strIn;
242string strLeft(
const string& strIn,
int const nWidth)
244 stringstream ss, spaces;
245 int nPadding = nWidth -
static_cast<int>(strIn.size());
247 for (
int i = 0; i < nPadding; ++i)
250 ss << strIn << spaces.str();
257string strLeft(
const char* pchIn,
int const nWidth)
260 stringstream ss, spaces;
261 int nPadding = nWidth -
static_cast<int>(strIn.size());
263 for (
int i = 0; i < nPadding; ++i)
266 ss << strIn << spaces.str();
273string strRightPerCent(
double const d1,
double const d2,
int const nWidth,
int const nDigits,
bool const bShowDash)
276 ss << fixed << right;
282 ss.width(nWidth - 1);
294 double dResult = 100 * d1 / d2;
296 stringstream ssResult;
297 ssResult << fixed << right;
298 ssResult.precision(nDigits);
299 ssResult <<
"(" << dResult <<
"%)";
301 long int nResultWidth = ssResult.str().size();
303 for (
int i = 0; i < (nWidth - nResultWidth - 1); i++)
306 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....