fandago
Διακεκριμένο μέλος
Ο Ә□⌂щяңš αυτή τη στιγμή δεν είναι συνδεδεμένος. Είναι 40 ετών και μας γράφει απο Αθήνα (Αττική). Έχει γράψει 6,876 μηνύματα.
21-03-08
21:25
Έχεις δίκιο Bill, κατά την αλλαγή του τίτλου το ξέχασα.*To link που έδωσα είναι για visual C++ .Νομιζα οτι στον τίτλο ελεγε για VC++ , αλλά και η sprintf δουλεύει κανονικά.
Και μιας και εγώ μάλλον ήμουν off topic, δίνοντας οδηγίες για καθαρά C και C++ αντίστοιχα () και αφού δεν έχω ασχοληθεί με VC++ για να δω τι διαφορές υπάρχουν, ας δώσω ένα link που βρήκα στα γρήγορα που ίσως βοηθήσει:
Visual C++ Standard Library: setprecision
Σημείωση: Το μήνυμα αυτό γράφτηκε 16 χρόνια πριν. Ο συντάκτης του πιθανόν να έχει αλλάξει απόψεις έκτοτε.
fandago
Διακεκριμένο μέλος
Ο Ә□⌂щяңš αυτή τη στιγμή δεν είναι συνδεδεμένος. Είναι 40 ετών και μας γράφει απο Αθήνα (Αττική). Έχει γράψει 6,876 μηνύματα.
21-03-08
21:02
printf - C++ Reference
printf ("floats: %.2f", 3.1416);
θα βγάλει 3.14
Αυτό ζητάς;
Για παράδειγμα το:%[flags][width][.precision][length]specifier
Where specifier is the most significant one and defines the type and the interpretation of the value of the coresponding
For integer specifiers (d, i, o, u, x, X): precision specifies the minimum number of digits to be written. If the value to be written is shorter than this number, the result is padded with leading zeros. The value is not truncated even if the result is longer. A precision of 0 means that no character is written for the value 0.
For e, E and f specifiers: this is the number of digits to be printed after the decimal point.
For g and G specifiers: This is the maximum number of significant digits to be printed.
For s: this is the maximum number of characters to be printed. By default all characters are printed until the ending null character is encountered.
For c type: it has no effect.
When no precision is specified, the default is 1. If the period is specified without an explicit value for precision, 0 is assumed.
printf ("floats: %.2f", 3.1416);
θα βγάλει 3.14
Αυτό ζητάς;
Σημείωση: Το μήνυμα αυτό γράφτηκε 16 χρόνια πριν. Ο συντάκτης του πιθανόν να έχει αλλάξει απόψεις έκτοτε.