BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Formatting Currency
Goto page 1, 2  Next
 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage)
View previous topic :: View next topic  
Author Message
george
Guest





PostPosted: Tue Sep 26, 2006 12:31 am    Post subject: Formatting Currency Reply with quote



I can format a floating point item into a fixed size field, left
filled with zeroes and with a decimal point and 2 figures on
the RHS. E.g. sprintf( %09.2f )

But how do I do the same for a Currency field? I want to use Currency to avoid rounding errors.

George
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Tue Sep 26, 2006 2:00 am    Post subject: Re: Formatting Currency Reply with quote



"george" <zombacity (AT) aol (DOT) com> wrote in message
news:45182eac$1 (AT) newsgroups (DOT) borland.com...

Quote:
how do I do the same for a Currency field?

Have you looked at the FormatCurr() function yet?


Gambit
Back to top
george
Guest





PostPosted: Tue Sep 26, 2006 8:11 am    Post subject: Re: Formatting Currency Reply with quote



Thanks, I will experiment with that. But at first sight it does not seem to allow leading zeroes. And my help text does not say what format type to specify. I will try m. Are Currency values held as floating point? I am assuming that by using Currency I will avoid potential floating point rounding problems.

George

"Remy Lebeau \(TeamB\)" <no.spam (AT) no (DOT) spam.com> wrote:
Quote:

"george" <zombacity (AT) aol (DOT) com> wrote in message
news:45182eac$1 (AT) newsgroups (DOT) borland.com...

how do I do the same for a Currency field?

Have you looked at the FormatCurr() function yet?


Gambit

Back to top
george
Guest





PostPosted: Tue Sep 26, 2006 3:49 pm    Post subject: Re: Formatting Currency Reply with quote

"Remy Lebeau \(TeamB\)" <no.spam (AT) no (DOT) spam.com> wrote:
Quote:


Have you looked at the FormatCurr() function yet?


Gambit



Yes I have tried it, but something is going wrong.
The below code produces weird results.

X seems to be Ok and its value 1213.23 is shown OK
without any formatting.

But the next attempt seems to mix up the value and the format
string as follows:

%112132s

the leading % and 1 appear on the screen followd by the pounds

part of the value and then the trailing 2s from the format
string.
Any ideas will be welcome.

void __fastcall TForm1::AddRE(Currency X)
{
String line=X;
RE->Lines->Append(line);
line = FormatCurr("%10.2s",X);
RE->Lines->Append(line);
}
Back to top
Minas
Guest





PostPosted: Tue Sep 26, 2006 4:10 pm    Post subject: Re: Formatting Currency Reply with quote

Ο "george" <zombacity (AT) aol (DOT) com> έγραψε στο μήνυμα
news:451905a5$1 (AT) newsgroups (DOT) borland.com...

Quote:
RE->Lines->Append(line);
line = FormatCurr("%10.2s",X);
RE->Lines->Append(line);

Hi George

Try something similar

double x = 1234.89; // or Currency x = 1234.89
ShowMessage( FormatCurr( "0,###,###,###.00",x) );

_minas harokopos

------
"Only the virtue's conquests have certainty" Sofokleous Erephyle
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Tue Sep 26, 2006 10:11 pm    Post subject: Re: Formatting Currency Reply with quote

"george" <zombacity (AT) aol (DOT) com> wrote in message
news:451905a5$1 (AT) newsgroups (DOT) borland.com...

Quote:
line = FormatCurr("%10.2s",X);

That is not the correct way to format a Currency value. You are trying to
use a C language printf() format string. Such format strngs do not apply to
the VCL at all. The VCL has its own rules for format strings. These are
explained in the VCL documentation, such as for the FormatFloat() function.
Your format string needs to look more like the following instead:

line = FormatCurr("#,##0.00", X);


Gambit
Back to top
george
Guest





PostPosted: Wed Sep 27, 2006 2:35 am    Post subject: Re: Formatting Currency Reply with quote

OK I am progressing. I was following my help text instructions.
What you and another respondent suggest works much better, but I haven't yet found how to right align a column of figures. I can only do so if I fill LHS with zeroes, but I need spaces.

George

"Remy Lebeau \(TeamB\)" <no.spam (AT) no (DOT) spam.com> wrote:
Quote:

The VCL has its own rules for format strings. These are
explained in the VCL documentation, such as for the FormatFloat() function.
Your format string needs to look more like the following instead:

line = FormatCurr("#,##0.00", X);


Gambit

Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Wed Sep 27, 2006 3:44 am    Post subject: Re: Formatting Currency Reply with quote

"george" <zombacity (AT) aol (DOT) com> wrote in message
news:45199d24$1 (AT) newsgroups (DOT) borland.com...

Quote:
I haven't yet found how to right align a column of figures. I can
only do so if I fill LHS with zeroes, but I need spaces.

What exactly are you trying to align? How are you displaying the values to
the user?


Gambit
Back to top
george
Guest





PostPosted: Wed Sep 27, 2006 4:24 pm    Post subject: Re: Formatting Currency Reply with quote

I want to show a column of amounts, like a bank statement, with the decimal points one above another. I other words with their RHS lined up nicely. I use fixed size font so that I can just count the characters. I display the data in a RichEdit and give the user the option to print it.


"Remy Lebeau \(TeamB\)" <no.spam (AT) no (DOT) spam.com> wrote:
Quote:

What exactly are you trying to align? How are you displaying the values to
the user?


Gambit



Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Wed Sep 27, 2006 10:35 pm    Post subject: Re: Formatting Currency Reply with quote

"george" <zombacity (AT) aol (DOT) com> wrote in message
news:451a5f8a$1 (AT) newsgroups (DOT) borland.com...

Quote:
I display the data in a RichEdit and give the user the option to print it.

You can right-align text in a TRichEdit. It has an Alignment property for
that, which applies to the entire contents of the TRichEdit. If you are
trying to align a particular block of text and not the entire contents, then
put the desired test into its own Paragraph, and then use the
Paragraph->Alignment property instead.


Gambit
Back to top
george
Guest





PostPosted: Thu Sep 28, 2006 10:14 pm    Post subject: Re: Formatting Currency Reply with quote

I am not sure that will work. For example sometimes I have 3
columns of amounts and want them all lined up.
I am looking at using Currency to avoid the rounding problems

which I occasionally get with float. Is there a better approach?

George.

"Remy Lebeau \(TeamB\)" <no.spam (AT) no (DOT) spam.com> wrote:
Quote:

"george" <zombacity (AT) aol (DOT) com> wrote in message
news:451a5f8a$1 (AT) newsgroups (DOT) borland.com...

I display the data in a RichEdit and give the user the option to print it.

You can right-align text in a TRichEdit. It has an Alignment property for
that, which applies to the entire contents of the TRichEdit. If you are
trying to align a particular block of text and not the entire contents, then
put the desired test into its own Paragraph, and then use the
Paragraph->Alignment property instead.


Gambit

Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Thu Sep 28, 2006 11:16 pm    Post subject: Re: Formatting Currency Reply with quote

"george" <zombacity (AT) aol (DOT) com> wrote in message
news:451c02f2$1 (AT) newsgroups (DOT) borland.com...

Quote:
I am not sure that will work. For example sometimes I have
3 columns of amounts and want them all lined up.

It will work fine. You already said that you are using a fixed-width font,
so just space the columns from each other using the same amount of padding,
and then you put each line that has columns into a paragraph and align it.

Otherwise, use a grid instead of a TRichEdit, such as a TStringGrid or
TListView.


Gambit
Back to top
george
Guest





PostPosted: Fri Sep 29, 2006 4:21 pm    Post subject: Re: Formatting Currency Reply with quote

OK, I can pad my field on LHS with zeroes using
line = FormatCurr( "0#########.00",X) ;
but there does not seem a way to pad with spaces, if I put a
space instead of the zero,nothing comes out.

So if I have 2 columns, the RHS column can be aligned to he RHS
of the control, but the preceding column entry's position will
depend on the value and number of digits used for the last
column. I am trying to avoid calclating a filler size which
depends on the text being displayed.

Part of my problem is that I seem to have a defective help
text. In that connection is there any way to download a good
help text?
Mine came with C++ Builder Personal version 6 Build 10.161. My

current help text leads me from FormatCurr to Format Strings

which says Format specifiers have the following form:

"%" [index ":"] ["-"] [width] ["." prec] type.; which is wrong.






"Remy Lebeau \(TeamB\)" <no.spam (AT) no (DOT) spam.com> wrote:
Quote:

put the desired test into its own Paragraph, and then use the
Paragraph->Alignment property instead.


Gambit

Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Sat Sep 30, 2006 12:39 am    Post subject: Re: Formatting Currency Reply with quote

"george" <zombacity (AT) aol (DOT) com> wrote in message
news:451d01a3$1 (AT) newsgroups (DOT) borland.com...

Quote:
OK, I can pad my field on LHS with zeroes using
line = FormatCurr( "0#########.00",X) ;

That is a very unusual way to pad it, since '#' says to store nothing if
there is no digit in that position. If you really want the number to be
padded with a minimum of 10 digits, then you should be using '0' instead of
'#':

line = FormatCurr( "0000000000.00", X);

Quote:
there does not seem a way to pad with spaces

No, there is not. If you need that, then you will have to pad the value
manually, ie:

line = FormatCurr( "0.00", X);
if( line.Length() < 13 )
line = AnsiString::StringOfChar(" ", 13-line.Length()) + line;

Quote:
So if I have 2 columns, the RHS column can be aligned to he RHS
of the control, but the preceding column entry's position will
depend on the value and number of digits used for the last
column.

I really think you should consider using a completely different approach to
your UI design. Trying to do columns in an edit control is not a very good
design.

Quote:
I am trying to avoid calclating a filler size which depends on the
text being displayed.

Sorry, but that is what you need to do.


Gambit
Back to top
Minas
Guest





PostPosted: Sat Sep 30, 2006 8:10 am    Post subject: Re: Formatting Currency Reply with quote

Ο "Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> έγραψε στο μήνυμα
news:451d7965$1 (AT) newsgroups (DOT) borland.com...

Quote:
line = FormatCurr( "0#########.00",X) ;

That is a very unusual way to pad it, since '#' says to store nothing if
there is no digit in that position.

"0#########.00" It works just fine .

Just put zeros on the beginning and the end of the format string .

try this

double x= 12345.050;
String line = FormatCurr( "0,###,###,###.##0",x) ;
ShowMessage(line);

_minas harokopos

------
"Only the virtue's conquests have certainty" Sofokleous Erephyle
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage) All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.