C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

sprintf (formatierte Ausgabe)

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (German)
View previous topic :: View next topic  
Author Message
Philip Diegmann
Guest





PostPosted: Sun Feb 06, 2005 4:28 pm    Post subject: sprintf (formatierte Ausgabe) Reply with quote



Hallo,

Ist es möglich die Auzahl der Nachkommastellen bei einer floating point
Ausgabe mit dem sprintf-Kommando zu begrenzen.

z.B.: sprintf(pszText, "%f", dNumber);


Gruß
Philip

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
Back to top
Thomas Maeder
Guest





PostPosted: Sun Feb 06, 2005 8:08 pm    Post subject: Re: sprintf (formatierte Ausgabe) Reply with quote



Philip Diegmann <black.ice (AT) t-online (DOT) de> writes:

Quote:
Ist es möglich die Auzahl der Nachkommastellen bei einer floating
point Ausgabe mit dem sprintf-Kommando zu begrenzen.

z.B.: sprintf(pszText, "%f", dNumber);

Mit sprintf geht das nicht, aber mit snprintf:

int snprintf(char *str, size_t size, const char *format, ...);

....

The functions snprintf
and vsnprintf do not write more than size bytes (including
the trailing ''). If the output was truncated due to
this limit then the return value is the number of charac­
ters (not including the trailing '') which would have
been written to the final string if enough space had been
available. Thus, a return value of size or more means that
the output was truncated. (See also below under NOTES.)


snprintf ist aber erst seit C99 im Standard, gehört also streng
genommen nicht zu Standard C++.

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de

Back to top
King Leo - Martin Oberzal
Guest





PostPosted: Sun Feb 06, 2005 10:31 pm    Post subject: Re: sprintf (formatierte Ausgabe) Reply with quote



Philip Diegmann wrote:

Quote:
Ist es möglich die Auzahl der Nachkommastellen bei einer floating point
Ausgabe mit dem sprintf-Kommando zu begrenzen.

z.B.: sprintf(pszText, "%f", dNumber);

#include <stdio.h>

int main()
{
printf( "%f t %.2fn", 1.0/3.0, 1.0/3.0 );
}


martin@chello212186192051:~> ./foo2
0.333333 0.33

Gruß, Martin!

--
Gebrauchtwagen => http://www.austromobil.at
Fuer Privatpersonen kostenlos!

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de

Back to top
Dirk Jagdmann
Guest





PostPosted: Sun Feb 06, 2005 10:36 pm    Post subject: Re: sprintf (formatierte Ausgabe) Reply with quote

Quote:
Ist es möglich die Auzahl der Nachkommastellen bei einer floating point
Ausgabe mit dem sprintf-Kommando zu begrenzen.

printf("%.2f", 3,1498) := 3.15
printf("%.2f", 3.1411) := 3.14

rundet sogar.
--
---> doj / cubic
----> http://cubic.org/~doj
-----> http://llg.cubic.org

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de

Back to top
Philip Diegmann
Guest





PostPosted: Mon Feb 07, 2005 7:00 pm    Post subject: Re: sprintf (formatierte Ausgabe) Reply with quote

Danke für die Antworten!
Es hat geklappt.

Gruß
Philip



Dirk Jagdmann wrote:
Quote:
Ist es möglich die Auzahl der Nachkommastellen bei einer floating
point Ausgabe mit dem sprintf-Kommando zu begrenzen.


printf("%.2f", 3,1498) := 3.15
printf("%.2f", 3.1411) := 3.14

rundet sogar.

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (German) 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.