113 lines
1.7 KiB
C++
113 lines
1.7 KiB
C++
#ifndef _SQL_MONEY_HPP_
|
|
#define _SQL_MONEY_HPP_
|
|
#ifndef _COMMON_STRING_HPP_
|
|
#include <common/string.hpp>
|
|
#endif
|
|
#ifndef _COMMON_STDIO_HPP_
|
|
#include <common/stdio.hpp>
|
|
#endif
|
|
|
|
class Money
|
|
{
|
|
public:
|
|
Money(void);
|
|
Money(double value);
|
|
Money(const Money &someMoney);
|
|
virtual ~Money();
|
|
Money &operator=(const Money &someMoney);
|
|
operator String(void);
|
|
void format(const String &strFormat);
|
|
const String &format(void)const;
|
|
double value(void)const;
|
|
void value(double value);
|
|
String toString(void)const;
|
|
private:
|
|
double mValue;
|
|
String mFormat;
|
|
};
|
|
|
|
|
|
inline
|
|
Money::Money(void)
|
|
: mValue(0.00), mFormat("% 12.2lf")
|
|
{
|
|
}
|
|
|
|
inline
|
|
Money::Money(double value)
|
|
: mValue(value), mFormat("% 12.2lf")
|
|
{
|
|
}
|
|
|
|
inline
|
|
Money::Money(const Money &someMoney)
|
|
{
|
|
*this=someMoney;
|
|
}
|
|
|
|
inline
|
|
Money::~Money()
|
|
{
|
|
}
|
|
|
|
inline
|
|
Money &Money::operator=(const Money &someMoney)
|
|
{
|
|
format(someMoney.format());
|
|
value(someMoney.value());
|
|
return *this;
|
|
}
|
|
|
|
inline
|
|
Money::operator String(void)
|
|
{
|
|
return toString();
|
|
}
|
|
|
|
inline
|
|
String Money::toString(void)const
|
|
{
|
|
String strString;
|
|
String moneyString;
|
|
|
|
::sprintf(strString,mFormat,mValue);
|
|
char *strPtr=strString;
|
|
char *strRoot=strPtr;
|
|
while(*strPtr!='.')strPtr++;
|
|
while(TRUE)
|
|
{
|
|
for(int count=0;count<3&&strPtr>strRoot&&*strPtr!=' ';count++)strPtr--;
|
|
if(strPtr<=strRoot)break;
|
|
moneyString.insert(strPtr);
|
|
if(*(strPtr-1)!=' ')moneyString.insert(",");
|
|
*strPtr=0;
|
|
}
|
|
moneyString.insert("$");
|
|
return moneyString;
|
|
}
|
|
|
|
inline
|
|
void Money::format(const String &strFormat)
|
|
{
|
|
mFormat=strFormat;
|
|
}
|
|
|
|
inline
|
|
const String &Money::format(void)const
|
|
{
|
|
return mFormat;
|
|
}
|
|
|
|
inline
|
|
double Money::value(void)const
|
|
{
|
|
return mValue;
|
|
}
|
|
|
|
inline
|
|
void Money::value(double value)
|
|
{
|
|
mValue=value;
|
|
}
|
|
#endif
|