Visualizzazione dei risultati da 1 a 4 su 4
  1. #1

    [C++]Output usando "cout"

    Ciao raga, mi chiedevo se c'è qualke parola chiave per fare in modo che viene stampato un numero "tipo float", solo con 2 cifre decimali.

  2. #2
    Sets the number of digits printed to the right of the decimal point. This applies to all subsequent floating point numbers written to that output stream. However, this won't make floating-point "integers" print with a decimal point. It's necessary to use fixed for that effect. Equivalent to cout.precision(n);
    codice:
    #include <iostream>
    #include <iomanip>
    
    using namespace std;
    
    int main (void) {
      double num =3.14159;
      cout << setprecision (3) << num << endl;
    }
    "Se riesci a passare un pomeriggio assolutamente inutile in modo assolutamente inutile, hai imparato a vivere."

  3. #3
    Si, ma in questo modo se scrivo setprecision(2). e il numero è il numero è 128,5, mi stampa 12. io invece vorrei che mi stampasse il NUMERO INTERO, e solo le prime due cifre decimali.
    CIoè
    Num= 458.1478 ---->458.14
    Num= 457214.124---->457214.12

  4. #4
    Hai letto cosa avevo riportato nel post precedente?

    However, this won't make floating-point "integers" print with a decimal point. It's necessary to use fixed for that effect.

    codice:
    #include <iostream>
    #include <iomanip>
    
    using namespace std;
    
    int main()
    {
    	double num = 129.146734689734698734698347;
    	cout << setiosflags(ios::fixed) << setprecision(2) << num;
    	return 0;
    }
    "Se riesci a passare un pomeriggio assolutamente inutile in modo assolutamente inutile, hai imparato a vivere."

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.