0

Number of digits after dot in c++ using printf

In this code , i can print MY NUMBER with 2 numbers of digits after decimal point . MY NUMBER is 1.72627827... Code : printf( "%0.2f" , 1.72627827); ........... Now I want print MY NUMBER with N numbers of digits after decimal point . N is giveen by user with cin . How can i do that ?

5th Dec 2020, 6:29 PM
Bruce
3 Antworten
+ 2
int N; cin >> N; printf("%.*f", N, 1.72627827);
5th Dec 2020, 6:59 PM
rodwynnejones
rodwynnejones - avatar
+ 1
Thanks ... it works ! But what does it mean ? "%.*f"
5th Dec 2020, 11:37 PM
Bruce
+ 1
http://www.cplusplus.com/reference/cstdio/printf/ All about printf you need to know!
6th Dec 2020, 1:26 AM
Hima
Hima - avatar