+ 2

How to display a 0 after a decimal

If I want to show a dollar amount like $1.50, how do I get the 0 to display?

22nd Feb 2017, 9:36 PM
Thomas Kimball
3 Respuestas
+ 1
When I use float, the 0 in the hundreths place does not display. Do I need to use double?
22nd Feb 2017, 10:35 PM
Thomas Kimball
+ 1
Here's an example: #include<iostream> #include <iomanip> using namespace std; int main() { float a=111.5; float b= 2.333333; cout << fixed << setprecision(2); cout << "Your a= " <<a; cout << "Your b= " <<b; return 0; } You have to include this line at the beginning of your code: cout << fixed << setprecision(2); And don't forget to include iomanip library! :)
22nd Feb 2017, 11:23 PM
Michał Maczuga
Michał Maczuga - avatar
0
i think u should write float instead of int
22nd Feb 2017, 10:33 PM
moahmed abdelhakim hacine
moahmed abdelhakim hacine - avatar