mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
introduce more flexible, robust format handling
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@952 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
6312a46216
commit
a5c17b4111
@ -108,6 +108,7 @@ xaccInitPriceCell (PriceCell *cell)
|
||||
xaccInitBasicCell( &(cell->cell));
|
||||
cell->amount = 0.0;
|
||||
cell->blank_zero = 1;
|
||||
cell->prt_format = strdup ("%.2f");
|
||||
|
||||
SET ( &(cell->cell), "");
|
||||
|
||||
@ -121,6 +122,7 @@ void
|
||||
xaccDestroyPriceCell (PriceCell *cell)
|
||||
{
|
||||
cell->amount = 0.0;
|
||||
free (cell->prt_format); cell->prt_format = 0x0;
|
||||
xaccDestroyBasicCell ( &(cell->cell));
|
||||
}
|
||||
|
||||
@ -135,7 +137,7 @@ void xaccSetPriceCellValue (PriceCell * cell, double amt)
|
||||
if (cell->blank_zero && (VERY_SMALL > amt) && ((-VERY_SMALL) < amt)) {
|
||||
buff[0] = 0x0;
|
||||
} else {
|
||||
sprintf (buff, "%.3f", amt);
|
||||
sprintf (buff, cell->prt_format, amt);
|
||||
}
|
||||
SET ( &(cell->cell), buff);
|
||||
|
||||
@ -145,21 +147,13 @@ void xaccSetPriceCellValue (PriceCell * cell, double amt)
|
||||
|
||||
/* ================================================ */
|
||||
|
||||
void xaccSetAmountCellValue (PriceCell * cell, double amt)
|
||||
void xaccSetPriceCellFormat (PriceCell * cell, char * fmt)
|
||||
{
|
||||
char buff[40];
|
||||
cell->amount = amt;
|
||||
if (cell->prt_format) free (cell->prt_format);
|
||||
cell->prt_format = strdup (fmt);
|
||||
|
||||
/* if amount is zero, and blanking is set, then print blank */
|
||||
if (cell->blank_zero && (VERY_SMALL > amt) && ((-VERY_SMALL) < amt)) {
|
||||
buff[0] = 0x0;
|
||||
} else {
|
||||
sprintf (buff, "%.2f", amt);
|
||||
}
|
||||
SET ( &(cell->cell), buff);
|
||||
|
||||
/* set the cell color to red if the value is negative */
|
||||
COLORIZE (cell, amt);
|
||||
/* make sure that the cell is updated with the new format */
|
||||
xaccSetPriceCellValue (cell, cell->amount);
|
||||
}
|
||||
|
||||
/* ================================================ */
|
||||
@ -179,11 +173,11 @@ void xaccSetDebCredCellValue (PriceCell * deb,
|
||||
SET ( &(deb->cell), "");
|
||||
} else
|
||||
if (0.0 < amt) {
|
||||
sprintf (buff, "%.2f", amt);
|
||||
sprintf (buff, cred->prt_format, amt);
|
||||
SET ( &(cred->cell), buff);
|
||||
SET ( &(deb->cell), "");
|
||||
} else {
|
||||
sprintf (buff, "%.2f", -amt);
|
||||
sprintf (buff, deb->prt_format, -amt);
|
||||
SET ( &(cred->cell), "");
|
||||
SET ( &(deb->cell), buff);
|
||||
}
|
||||
@ -194,15 +188,10 @@ void xaccSetDebCredCellValue (PriceCell * deb,
|
||||
static void
|
||||
PriceSetValue (BasicCell *_cell, const char *str)
|
||||
{
|
||||
char buff[40];
|
||||
PriceCell *cell = (PriceCell *) _cell;
|
||||
double amt = xaccParseUSAmount (str);
|
||||
|
||||
SET (_cell, str);
|
||||
|
||||
cell->amount = xaccParseUSAmount (str);
|
||||
|
||||
sprintf (buff, "%.2f", cell->amount);
|
||||
SET ( &(cell->cell), buff);
|
||||
xaccSetPriceCellValue (cell, amt);
|
||||
}
|
||||
|
||||
/* --------------- end of file ---------------------- */
|
||||
|
@ -52,9 +52,9 @@
|
||||
|
||||
typedef struct _PriceCell {
|
||||
BasicCell cell;
|
||||
double amount; /* the amount associated with this cell */
|
||||
double amount; /* the amount associated with this cell */
|
||||
short blank_zero; /* controls printing of zero values */
|
||||
|
||||
char *prt_format; /* controls display of value; printf format */
|
||||
} PriceCell;
|
||||
|
||||
/* installs a callback to handle price recording */
|
||||
@ -65,8 +65,8 @@ void xaccDestroyPriceCell (PriceCell *);
|
||||
/* updates amount, string format is three decimal places */
|
||||
void xaccSetPriceCellValue (PriceCell *, double amount);
|
||||
|
||||
/* updates amount, string format is two decimal places */
|
||||
void xaccSetAmountCellValue (PriceCell *, double amount);
|
||||
/* use printf-style format to control display */
|
||||
void xaccSetPriceCellFormat (PriceCell *, char * fmt);
|
||||
|
||||
/* updates two cells; the deb cell if amt is negative,
|
||||
* the credit cell if amount is positive, and makes the other cell
|
||||
|
@ -466,6 +466,11 @@ void xaccInitSplitRegister (SplitRegister *reg, int type)
|
||||
xaccSetPriceCellValue (reg->creditCell, 0.0);
|
||||
xaccSetPriceCellValue (reg->valueCell, 0.0);
|
||||
|
||||
/* use three decimal places to print share-related info.
|
||||
* The format is a printf-style format for a double. */
|
||||
xaccSetPriceCellFormat (reg->shrsCell, "%.3f");
|
||||
xaccSetPriceCellFormat (reg->priceCell, "%.3f");
|
||||
|
||||
/* -------------------------------- */
|
||||
/* define how traversal works */
|
||||
configTraverse (reg);
|
||||
|
Loading…
Reference in New Issue
Block a user