Board index » cppbuilder » FormatFloat

FormatFloat


2004-02-06 09:10:48 PM
cppbuilder15
I use BCB 5 , Win98 ,dBaseIV (which is made with database desktop)
I'm writing an application, which is solve some financial questions.
I use FormatFloat command to change the currency format (for example 1000 to
1.000,00), and the formated currency (AnsiString) put in the database.
My problem is:
If I try to convert the AnsiString value (StrToFloat(...)) which is more
than 999,00 (for example 1.000,00) to float value the error is:
" '1.000,00' is not a valid floating point value"
How can I convert it correctly?
 
 

Re:FormatFloat

Hello Guba,
The StrToFloat function depends on the Regional Settings of your OS. Look for "DecimalSeparator" and "ThousandSeparator" in the help file.
You can set the DecimalSeparator character as "," if you need. Set the ThousandSeparator too.
HTH
Jayme.
"Guba" < XXXX@XXXXX.COM >wrote in message news: XXXX@XXXXX.COM ...
Quote
I use BCB 5 , Win98 ,dBaseIV (which is made with database desktop)
I'm writing an application, which is solve some financial questions.
I use FormatFloat command to change the currency format (for example 1000 to
1.000,00), and the formated currency (AnsiString) put in the database.
My problem is:
If I try to convert the AnsiString value (StrToFloat(...)) which is more
than 999,00 (for example 1.000,00) to float value the error is:
" '1.000,00' is not a valid floating point value"
How can I convert it correctly?



 

Re:FormatFloat

I've changed the Regional Settings of my OS but it's not worth a straw !
I don't know how to set the "DecimalSeparator" and "ThousandSeparator", can
you explain me how does it work?
Or if you have any example, can you send it to me?
Thanks
"Jayme Jeffman Filho" < XXXX@XXXXX.COM >wrote in message
Hello Guba,
The StrToFloat function depends on the Regional Settings of your OS. Look
for "DecimalSeparator" and "ThousandSeparator" in the help file.
You can set the DecimalSeparator character as "," if you need. Set the
ThousandSeparator too.
HTH
Jayme.
"Guba" < XXXX@XXXXX.COM >wrote in message
Quote
I use BCB 5 , Win98 ,dBaseIV (which is made with database desktop)
I'm writing an application, which is solve some financial questions.
I use FormatFloat command to change the currency format (for example 1000
to
1.000,00), and the formated currency (AnsiString) put in the database.
My problem is:
If I try to convert the AnsiString value (StrToFloat(...)) which is more
than 999,00 (for example 1.000,00) to float value the error is:
" '1.000,00' is not a valid floating point value"
How can I convert it correctly?



 

{smallsort}

Re:FormatFloat

Hello Guba,
I checked the help file for you and I found there the text bellow :
"Category
floating point conversion routines
extern PACKAGE Extended __fastcall StrToFloat(const AnsiString S);
Description
Use StrToFloat to convert an AnsiString, S, to a floating-point value. S must consist of an optional sign (+ or -), a string of digits with an optional decimal point, and an optional mantissa. The mantissa consists of 'E' or 'e' followed by an optional sign (+ or -) and a whole number. Leading and trailing blanks are ignored.
The DecimalSeparator global variable defines the character that must be used as a decimal point. Thousand separators and currency symbols are not allowed in the string. If S doesn't contain a valid value, StrToFloat throws an EConvertError exception. "
So the thousand separator is not allowed in the text to convert. The same happen with StrToCurr, you can check the help file yourself.
HTH
Jayme.
"Guba" < XXXX@XXXXX.COM >wrote in message news: XXXX@XXXXX.COM ...
Quote
I've changed the Regional Settings of my OS but it's not worth a straw !
I don't know how to set the "DecimalSeparator" and "ThousandSeparator", can
you explain me how does it work?
Or if you have any example, can you send it to me?
Thanks


"Jayme Jeffman Filho" < XXXX@XXXXX.COM >wrote in message
news:402399cf$ XXXX@XXXXX.COM ...
Hello Guba,

The StrToFloat function depends on the Regional Settings of your OS. Look
for "DecimalSeparator" and "ThousandSeparator" in the help file.

You can set the DecimalSeparator character as "," if you need. Set the
ThousandSeparator too.

HTH

Jayme.

"Guba" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...
>I use BCB 5 , Win98 ,dBaseIV (which is made with database desktop)
>I'm writing an application, which is solve some financial questions.
>I use FormatFloat command to change the currency format (for example 1000
to
>1.000,00), and the formated currency (AnsiString) put in the database.
>My problem is:
>If I try to convert the AnsiString value (StrToFloat(...)) which is more
>than 999,00 (for example 1.000,00) to float value the error is:
>" '1.000,00' is not a valid floating point value"
>How can I convert it correctly?
>
>
>



 

Re:FormatFloat

float f=3.24;
AnsiString str;
str.FormatFloat("$##.00",f);
ShowMessage(str);
str = FormatFloat("$##.00",f);
ShowMessage(str);
The first ShowMessage is blank. The 2nd one works. why?
 

Re:FormatFloat

Not sure, but you need this:
str = str.FormatFloat( "$##.00", f );
--
Best regards,
Vladimir Stefanovic
"Mike Margerum" < XXXX@XXXXX.COM >wrote in message
Quote
float f=3.24;
AnsiString str;
str.FormatFloat("$##.00",f);
ShowMessage(str);
str = FormatFloat("$##.00",f);
ShowMessage(str);

The first ShowMessage is blank. The 2nd one works. why?
 

Re:FormatFloat

On Mon, 14 Mar 2005 12:43:11 -0500
Mike Margerum < XXXX@XXXXX.COM >wrote:
Quote
float f=3.24;
AnsiString str;
str.FormatFloat("$##.00",f);
ShowMessage(str);
str = FormatFloat("$##.00",f);
ShowMessage(str);

The first ShowMessage is blank. The 2nd one works. why?
I vaguely recall FormatFloat being a class method of ansistrings. It returns the formatted value. (AnsiString.FormatFloat(...) would be clearer, but that is delphi ->c++ heritage?)
Micha
 

Re:FormatFloat

"Vladimir Stefanovic" < XXXX@XXXXX.COM >wrote in
Quote
Not sure, but you need this:
str = str.FormatFloat( "$##.00", f );

I think it's because the FormatFloat method of the AnsiString is a static
method, not an instance method, and returns a new instance of AnsiString.
FormatFloat (the global method) does the same, but is not invoked as a
static member.
mr_organic
 

Re:FormatFloat

Mike Margerum wrote:
Quote
float f=3.24;
AnsiString str;
str.FormatFloat("$##.00",f);
ShowMessage(str);
str = FormatFloat("$##.00",f);
ShowMessage(str);

The first ShowMessage is blank. The 2nd one works. why?
In the first case, you have an emtry string, then told it to format a float. However, you never
told it to store it anywhere. It only used the objects ability to format the float.
Try ShowMessage(str.FormatFloat("$##.00",f)), or better yet ShowMessage(FormatFloat("$##.00",f));
--
-Michael Gillen
 

Re:FormatFloat

AHHHH i c. I just assumed it would operate on the object invoking it. lol
Thx
mr_organic wrote:
Quote
"Vladimir Stefanovic" < XXXX@XXXXX.COM >wrote in
news: XXXX@XXXXX.COM :


>Not sure, but you need this:
>str = str.FormatFloat( "$##.00", f );
>


I think it's because the FormatFloat method of the AnsiString is a static
method, not an instance method, and returns a new instance of AnsiString.
FormatFloat (the global method) does the same, but is not invoked as a
static member.

mr_organic
 

Re:FormatFloat

The thing that made me assume it wasnt static was because the sprintf
method isnt static. Strange.
mr_organic wrote:
Quote
"Vladimir Stefanovic" < XXXX@XXXXX.COM >wrote in
news: XXXX@XXXXX.COM :


>Not sure, but you need this:
>str = str.FormatFloat( "$##.00", f );
>


I think it's because the FormatFloat method of the AnsiString is a static
method, not an instance method, and returns a new instance of AnsiString.
FormatFloat (the global method) does the same, but is not invoked as a
static member.

mr_organic
 

Re:FormatFloat

Mike Margerum < XXXX@XXXXX.COM >wrote in
Quote
The thing that made me assume it wasnt static was because the sprintf
method isnt static. Strange.

I've noticed that many static methods of classes are aliased as globals:
Trim(), IntToStr(), FormatDateTime(), and so on. It might just be a
convenience thing, but I'm not sure. For consistency, and to make the
conversion clear, I generally use the static method of the class and not
the global method, like so:
I write
AnsiString strFoo = strTemp.Trim().LowerCase();
instead of
AnsiString strFoo = Trim(strTemp);
strFoo = LowerCase(strFoo);
It condenses the code without compromising clarity.
mr_organic
 

Re:FormatFloat

On 16 Mar 2005 05:28:35 -0800
"mr_organic" < XXXX@XXXXX.COM >wrote:
Quote
AnsiString strFoo = Trim(strTemp);
strFoo = LowerCase(strFoo);

It condenses the code without compromising clarity.
Why not:
AnsiString strFoo = LowerCase(Trim(strTemp));
?
Micha
 

Re:FormatFloat

It condenses the code without compromising clarity.
Quote

Why not:

AnsiString strFoo = LowerCase(Trim(strTemp));

?

Micha

*Shrug*. No reason. Just a style thing, I guess. One's as good as the
other.
mr_organic
 

Re:FormatFloat

"mr_organic" < XXXX@XXXXX.COM >wrote in message
Quote
It condenses the code without compromising clarity.
>
>Why not:
>
>AnsiString strFoo = LowerCase(Trim(strTemp));
>
>?
>
>Micha
>

*Shrug*. No reason. Just a style thing, I guess. One's as good as the
other.
I would prefer if static functions were called with the namespace/class name
to show that they're static. It's probably not a popular opinion but
I would prefer:
AnsiString strFoo = AnsiString::LowerCase(AnsiString::Trim(strTemp));
This indicates that it's a static function and in the AnsiString namespace.