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 

format question

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Native API)
View previous topic :: View next topic  
Author Message
Karim
Guest





PostPosted: Tue May 24, 2005 9:36 am    Post subject: format question Reply with quote





Hi,

is there any API to convert a string or an int to a specific format? For example:
my input: 12.3 output: 000012.3
345.9 000345.9

Thanks a lot
Back to top
JD
Guest





PostPosted: Tue May 24, 2005 11:39 am    Post subject: Re: format question Reply with quote




"Karim" <Karim (AT) noemail (DOT) com> wrote:
Quote:

is there any API to convert a string or an int to a specific format? For example:
my input: 12.3 output: 000012.3
345.9 000345.9

That can be accomplished using sprintf or AnsiString.sprintf:

// assumes Buffer is a char*
sprintf( Buffer, "%06f", SomeFloat );

// assumes Buffer is an AnsiString
Buffer.sprintf("%06f", SomeFloat );

~ JD


Back to top
Karim
Guest





PostPosted: Tue May 24, 2005 2:35 pm    Post subject: Re: format question Reply with quote





Thanks JD,
What about if I want to change the number after the point in two numbers? 12.3 becomes 000012.30

Thanks

"JD" <nospam (AT) nospam (DOT) com> wrote:
Quote:

"Karim" <Karim (AT) noemail (DOT) com> wrote:

is there any API to convert a string or an int to a specific format? For example:
my input: 12.3 output: 000012.3
345.9 000345.9

That can be accomplished using sprintf or AnsiString.sprintf:

// assumes Buffer is a char*
sprintf( Buffer, "%06f", SomeFloat );

// assumes Buffer is an AnsiString
Buffer.sprintf("%06f", SomeFloat );

~ JD



Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Tue May 24, 2005 5:27 pm    Post subject: Re: format question Reply with quote


"Karim" <Karim (AT) noemail (DOT) com> wrote


Quote:
is there any API to convert a string or an int to a specific format?

The Win32 API has a wsprintf() function.


Gambit



Back to top
JD
Guest





PostPosted: Tue May 24, 2005 10:24 pm    Post subject: Re: format question Reply with quote


"Karim" <karim (AT) noemail (DOT) com> wrote:
Quote:

What about if I want to change the number after the point in
two numbers? 12.3 becomes 000012.30

Break the float into 2 ints:

int WholePortion = SomeFloat;
int DecimalPortion = (SomeFloat - WholePortion) * 100;
Buffer.sprintf("%06d.%d", WholePortion, DecimalPortion );

~ JD


Back to top
Ed Mulroy [TeamB]
Guest





PostPosted: Wed May 25, 2005 1:11 am    Post subject: Re: format question Reply with quote

Quote:
What about if I want to change the number after the
point in two numbers? 12.3 becomes 000012.30

---------------------
C:Documents and SettingsAdministratorMy DocumentsLookatq099
Quote:
type test.cpp
#include


int main()
{
double d = 12.3;

printf("%09.2fn", d);
return 0;
}

C:Documents and SettingsAdministratorMy DocumentsLookatq099
Quote:
bcc32 -WCR test
Borland C++ 5.6.4 for Win32 Copyright (c) 1993, 2002 Borland

test.cpp:
Turbo Incremental Link 5.66 Copyright (c) 1997-2002 Borland

C:Documents and SettingsAdministratorMy DocumentsLookatq099
Quote:
test
000012.30


C:Documents and SettingsAdministratorMy DocumentsLookatq099
Quote:

---------------------


.. Ed

Quote:
Karim wrote in message
news:42933ba8$1 (AT) newsgroups (DOT) borland.com...



Back to top
Christian Lotze
Guest





PostPosted: Wed May 25, 2005 7:59 am    Post subject: Re: format question Reply with quote

Remy Lebeau (TeamB) schrieb:
Quote:
"Karim" <Karim (AT) noemail (DOT) com> wrote in message
news:4292f5a8$1 (AT) newsgroups (DOT) borland.com...


is there any API to convert a string or an int to a specific format?


The Win32 API has a wsprintf() function.

wich doesn't work with floating point numbers,
use sprintf, works also in windows.

Or use FmtStr, AnsiString::sprintf or similar formatting functions

Quote:

Gambit


Christian

Back to top
Heinrich Wolf
Guest





PostPosted: Wed May 25, 2005 6:04 pm    Post subject: Re: format question Reply with quote


"JD" <nospam (AT) nospam (DOT) com> schrieb im Newsbeitrag
news:4293a9ba$1 (AT) newsgroups (DOT) borland.com...
....

Quote:
int WholePortion = SomeFloat;
int DecimalPortion = (SomeFloat - WholePortion) * 100;
Buffer.sprintf("%06d.%d", WholePortion, DecimalPortion );

That will give wrong output on e.g. SomeFloat = 25.06 !
The Format for WholePortion and DecimalPortion must be
"%06d.%02d"

But why for heaven's sake not:
Buffer.sprintf("%06.2f", SomeFloat); ?



Back to top
Heinrich Wolf
Guest





PostPosted: Wed May 25, 2005 6:06 pm    Post subject: Re: format question Reply with quote


"Heinrich Wolf" <invalid (AT) invalid (DOT) invalid> schrieb im Newsbeitrag
news:3fjt23F88dlhU1 (AT) individual (DOT) net...
....
Quote:
Buffer.sprintf("%06.2f", SomeFloat); ?
I'm sorry: "%09.2f"




Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Native API) All times are GMT
Page 1 of 1

 
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.