Accueil > > > BIPNUM : CLASSE POUR NOMBRE MONÉTAIRE
BIPNUM : CLASSE POUR NOMBRE MONÉTAIRE
Information sur la source
Description
Cette classe permet de stocker des nombres monétaires. C'est à dire qui permet de stocker des chiffres décimaux en conservant l'intégrité de la valeur (contrairement aux float). La précision est de 18 chiffres pour la partie entière et 9 chiffres pour la partie décimale). La valeur nulle est gérée. Le nombre peut être formaté en sortie et en entrée (signe décimal, symbole des milliers, symbole monétaire, ...) Par exemple le nombre "1.234.567,89" est accepté en entrée et en sortie. Cette classe est particulièrement faite pour les nombres des bases de données et/ou les chiffres monétaire.
Source
- Le fichier header :
-
- //************************************************************************
- //* BipNUM Win V0.9.2 *
- //*----------------------------------------------------------------------*
- //* Header file for BipNUM Win *
- //* *
- //* *
- //* Licence : freeware *
- //************************************************************************
-
-
- // include BipNUM only one time
- #ifndef _BipNUM_
- #define _BipNUM_
-
- #include <iostream>
-
- typedef __int64 LONGLONG;
-
-
- // global define
- const long BP_DECIMAL = 1000000000; // add to decimal part of currency
- const long BP_DECIMALX2 = 2000000000; // BP_DECIMAL X 2
- const int BP_DEC_DIGIT = 9; // number of digit in decimal part
- const LONGLONG BP_MAX_INT = 1000000000000000000; // max value for integer part
- const unsigned long int BP_MAX_DEC = 1999999999; // max value for decimal part
-
-
- // structure define
- struct BP_STRUCT_CURRENCY // Currency structure
- {
- LONGLONG lBP_Integer; // integer value
- unsigned long int lBP_Decimal; // decimal value
- bool bBP_Negative; // true : the currency is negative
- bool bBP_Null; // true : the currency is null
- };
-
- struct BP_STRUCT_FORMAT // Format structure
- {
- int iBP_NumInt; // format:number of character before decimal sign
- int iBP_NumDec; // format:number of character after decimal sign
- std::string sBP_DecimalSign; // format:decimal sign
- std::string sBP_KiloSign; // format:kilo sign
- std::string sBP_CurrencySymbol; // format:currency symbol
- std::string sBP_LeadChar; // format:leading character (only 1 char)
- std::string sBP_Null; // null format
- bool bBP_TrailZero; // trailing zero
- };
-
-
-
- class BP_Currency
- {
- private:
- BP_STRUCT_CURRENCY BP_Cur; // Currency structure
- BP_STRUCT_FORMAT BP_Fmt; // Format structure
- int iBPError; // error code
-
- public:
- BP_Currency::BP_Currency (); // constructor
- BP_Currency::~BP_Currency (); // destructor
- BP_Currency::set (const std::string BP_SetString);
- BP_Currency::set (const long BP_Long);
- BP_Currency::setnull (void);
- std::string BP_Currency::str (void);
- BP_Currency::setstdformat (const int iBP_SetNumInt,
- const int iBP_SetNumDec,
- const std::string sBP_SetFormat);
- BP_Currency::setformat (const int iBP_SetNumInt,
- const int iBP_SetNumDec,
- const std::string sBP_SetDecimalSign,
- const std::string sBP_SetKiloSign,
- const std::string sBP_SetCurrencySymbol,
- const std::string sBP_SetLeadChar,
- const std::string sBP_SetNull,
- const bool bBP_TrailZero);
- BP_Currency::setformat (const std::string sBP_SetFormat);
- BP_Currency::reset (void);
- BP_STRUCT_FORMAT BP_Currency::getformat (void);
- bool BP_Currency::isnull (void);
- BP_Currency::copyvalue (BP_Currency BP_CurSource);
- BP_Currency::copyformat (BP_Currency BP_CurSource);
- int BP_Currency::geterror (void);
-
-
- // overload operator : currency
- BP_Currency BP_Currency::operator + (const BP_Currency& BPright);
- BP_Currency BP_Currency::operator - (const BP_Currency& BPright);
- BP_Currency BP_Currency::operator += (const BP_Currency& BPright);
- BP_Currency BP_Currency::operator -= (const BP_Currency& BPright);
- bool BP_Currency::operator == (const BP_Currency& BPright);
- bool BP_Currency::operator != (const BP_Currency& BPright);
- bool BP_Currency::operator > (const BP_Currency& BPright);
- bool BP_Currency::operator >= (const BP_Currency& BPright);
- bool BP_Currency::operator < (const BP_Currency& BPright);
- bool BP_Currency::operator <= (const BP_Currency& BPright);
- BP_Currency BP_Currency::operator ++ (int BPright);
- BP_Currency BP_Currency::operator -- (int BPright);
- friend std::ostream & operator << (std::ostream & os, const BP_Currency& BPright);
-
- // overload operator : long
- friend BP_Currency BP_Currency::operator + (const BP_Currency& BPleft, const long& BPright);
- friend BP_Currency BP_Currency::operator + (const long& BPleft, const BP_Currency& BPright);
- friend BP_Currency BP_Currency::operator - (const BP_Currency& BPleft, const long& BPright);
- friend BP_Currency BP_Currency::operator - (const long& BPleft, const BP_Currency& BPright);
- bool BP_Currency::operator == (const long& BPright);
- bool BP_Currency::operator != (const long& BPright);
- bool BP_Currency::operator > (const long& BPright);
- bool BP_Currency::operator >= (const long& BPright);
- bool BP_Currency::operator < (const long& BPright);
- bool BP_Currency::operator <= (const long& BPright);
- };
-
- #endif /* _BipNUM_ */
-
Le fichier header :
//************************************************************************
//* BipNUM Win V0.9.2 *
//*----------------------------------------------------------------------*
//* Header file for BipNUM Win *
//* *
//* *
//* Licence : freeware *
//************************************************************************
// include BipNUM only one time
#ifndef _BipNUM_
#define _BipNUM_
#include <iostream>
typedef __int64 LONGLONG;
// global define
const long BP_DECIMAL = 1000000000; // add to decimal part of currency
const long BP_DECIMALX2 = 2000000000; // BP_DECIMAL X 2
const int BP_DEC_DIGIT = 9; // number of digit in decimal part
const LONGLONG BP_MAX_INT = 1000000000000000000; // max value for integer part
const unsigned long int BP_MAX_DEC = 1999999999; // max value for decimal part
// structure define
struct BP_STRUCT_CURRENCY // Currency structure
{
LONGLONG lBP_Integer; // integer value
unsigned long int lBP_Decimal; // decimal value
bool bBP_Negative; // true : the currency is negative
bool bBP_Null; // true : the currency is null
};
struct BP_STRUCT_FORMAT // Format structure
{
int iBP_NumInt; // format:number of character before decimal sign
int iBP_NumDec; // format:number of character after decimal sign
std::string sBP_DecimalSign; // format:decimal sign
std::string sBP_KiloSign; // format:kilo sign
std::string sBP_CurrencySymbol; // format:currency symbol
std::string sBP_LeadChar; // format:leading character (only 1 char)
std::string sBP_Null; // null format
bool bBP_TrailZero; // trailing zero
};
class BP_Currency
{
private:
BP_STRUCT_CURRENCY BP_Cur; // Currency structure
BP_STRUCT_FORMAT BP_Fmt; // Format structure
int iBPError; // error code
public:
BP_Currency::BP_Currency (); // constructor
BP_Currency::~BP_Currency (); // destructor
BP_Currency::set (const std::string BP_SetString);
BP_Currency::set (const long BP_Long);
BP_Currency::setnull (void);
std::string BP_Currency::str (void);
BP_Currency::setstdformat (const int iBP_SetNumInt,
const int iBP_SetNumDec,
const std::string sBP_SetFormat);
BP_Currency::setformat (const int iBP_SetNumInt,
const int iBP_SetNumDec,
const std::string sBP_SetDecimalSign,
const std::string sBP_SetKiloSign,
const std::string sBP_SetCurrencySymbol,
const std::string sBP_SetLeadChar,
const std::string sBP_SetNull,
const bool bBP_TrailZero);
BP_Currency::setformat (const std::string sBP_SetFormat);
BP_Currency::reset (void);
BP_STRUCT_FORMAT BP_Currency::getformat (void);
bool BP_Currency::isnull (void);
BP_Currency::copyvalue (BP_Currency BP_CurSource);
BP_Currency::copyformat (BP_Currency BP_CurSource);
int BP_Currency::geterror (void);
// overload operator : currency
BP_Currency BP_Currency::operator + (const BP_Currency& BPright);
BP_Currency BP_Currency::operator - (const BP_Currency& BPright);
BP_Currency BP_Currency::operator += (const BP_Currency& BPright);
BP_Currency BP_Currency::operator -= (const BP_Currency& BPright);
bool BP_Currency::operator == (const BP_Currency& BPright);
bool BP_Currency::operator != (const BP_Currency& BPright);
bool BP_Currency::operator > (const BP_Currency& BPright);
bool BP_Currency::operator >= (const BP_Currency& BPright);
bool BP_Currency::operator < (const BP_Currency& BPright);
bool BP_Currency::operator <= (const BP_Currency& BPright);
BP_Currency BP_Currency::operator ++ (int BPright);
BP_Currency BP_Currency::operator -- (int BPright);
friend std::ostream & operator << (std::ostream & os, const BP_Currency& BPright);
// overload operator : long
friend BP_Currency BP_Currency::operator + (const BP_Currency& BPleft, const long& BPright);
friend BP_Currency BP_Currency::operator + (const long& BPleft, const BP_Currency& BPright);
friend BP_Currency BP_Currency::operator - (const BP_Currency& BPleft, const long& BPright);
friend BP_Currency BP_Currency::operator - (const long& BPleft, const BP_Currency& BPright);
bool BP_Currency::operator == (const long& BPright);
bool BP_Currency::operator != (const long& BPright);
bool BP_Currency::operator > (const long& BPright);
bool BP_Currency::operator >= (const long& BPright);
bool BP_Currency::operator < (const long& BPright);
bool BP_Currency::operator <= (const long& BPright);
};
#endif /* _BipNUM_ */
Conclusion
Les commentaires sont les bienvenus avant que j'attaque les opérations (addition, multiplication, ...).
Vous trouverez la documentation de la classe ici : http://bipcpp.free.fr/
Vous trouverez un démontrateur (source + exe) ici : http://bipcpp.free.fr/fr/bipnum/testnum.zip Une mini calculatrice qui utilise cette classe (source + exe) ici : http://bipcpp.free.fr/fr/bipgdi/BipCalc-v110.zip
Historique
- 15 juin 2005 23:37:30 :
- Surchage des opérateurs d'opération, de comparaison et de flux.
Pour les nombres BipCurrency et les long.
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
IMAGINE CUP 2012, MAKE A SIGN EN FINALEIMAGINE CUP 2012, MAKE A SIGN EN FINALE par junarnoalg
Voilà qui est fait, la nouvelle est officielle ! L'équipe belge "Make a Sign" va au pays des kangourous défendre son projet dans la catégorie Software Design. http://www.imaginecup.com/CompetitionsContent/Competition/WorldwideFinalists.aspx V...
Cliquez pour lire la suite de l'article par junarnoalg KINECT 1.5 IS OUT !KINECT 1.5 IS OUT ! par Vko
La version 1.5 du Kinect For Microsoft vient tout juste de sortir ! Plein de nouveautés: Tracking de squelette en Near Mode Détection en position assise Détection faciale avec un SDK dédié Documentation et des guideline (enfin) Un out...
Cliquez pour lire la suite de l'article par Vko LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) par richardc
Mise à jour des Web API du 14 Mai
Réservez dès maintenant votre journée du 20 juin pour le Windows Azure Dev Camp 2012 à Paris
Mise à jour de Team Foundation Service
MechCommander 2 sur Windows 8
Entity Framework 5 Release Candidate e...
Cliquez pour lire la suite de l'article par richardc REACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITERREACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITER par Groc
Une mauvaise utilisation de rx lors de l'écriture d'une couche d'accès à des services peut conduire à des cas embarassants avec des erreurs mal gérées, des appels qui ne partent lorsqu'ils le devraient, et même des résultats incorrects . le tout nuis...
Cliquez pour lire la suite de l'article par Groc SHAREPOINT BLOG SITE, PROBLèME D'ARCHIVESSHAREPOINT BLOG SITE, PROBLèME D'ARCHIVES par junarnoalg
Dernièrement, nous avons migré le site
myTIC
vers un nouveau serveur SharePoint 2010. Dans les contenus que nous vouloins récupérer, nous avions un certain nombre de blogs.
Nous avons utilisé les commandes Power...
Cliquez pour lire la suite de l'article par junarnoalg
Forum
MATRICE TEMPLATEMATRICE TEMPLATE par hjr2610
Cliquez pour lire la suite par hjr2610 RE : SAC A DOS RE : SAC A DOS par hadjkaddour
Cliquez pour lire la suite par hadjkaddour
Logiciels
sDEVIS-FACTURES vlPRO (8.1.0.3)SDEVIS-FACTURES VLPRO (8.1.0.3)sDEVIS-FACTURES vlPRO a été mis au point pour les particuliers, créateurs, entrepreneurs, artisa... Cliquez pour télécharger sDEVIS-FACTURES vlPRO 974 Application Server (12.2.4.6)974 APPLICATION SERVER (12.2.4.6)Développez de puissantes applications dans un environnement de 'cloud computing', clusterisé, séc... Cliquez pour télécharger 974 Application Server vPicture (1.4.2.1)VPICTURE (1.4.2.1)Avec vPicture, hébergez vos images facilement et rapidement.
vPicture est un utilitaire simple, ... Cliquez pour télécharger vPicture Easy-Planning (2.2.1.6)EASY-PLANNING (2.2.1.6)Easy-Planning permet de créer des plannings sous la représentation de diagrammes et est adapté au... Cliquez pour télécharger Easy-Planning COM-BACKUP (2.0)COM-BACKUP (2.0)
COM-BACKUP est un logiciel de sauvegarde qui permet de planifier les sauvegardes de vos dossiers ...
Cliquez pour télécharger COM-BACKUP
|