forked from daverio/LATfield2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathint2string.hpp
executable file
·47 lines (36 loc) · 888 Bytes
/
int2string.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifndef INT2STRING_HPP
#define INT2STRING_HPP
/*! \file int2string.hpp
\brief int2string a small function to convert integer to string
\author Neil Bevis
*/
#include <string>
using std::string;
/*!
\brief integer to string method
\param number : int, input integer
\param max : int, max number (to specify number of digit in the string.
\param zeropad : bool, true will pad zeros, fals will not. default is true.
\return string.
*/
string int2string(int number, int max = 999, bool zeropad = true)
{
string output;
char c;
int i;
//Get number of digits needed for max
int digits=1;
for(i=10; (i-1)<max; i*=10) digits++;
//Create string of length digits (padded with zeros)
for(i=0; i<digits; i++)
{
c = '0' + number%10;
if(c!='0' || zeropad)
{
output = c + output;
}
number /= 10;
}
return output;
}
#endif