Skip to content

Instantly share code, notes, and snippets.

@ashwani-pandey
Last active January 3, 2016 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashwani-pandey/14c1570245a2947ef053 to your computer and use it in GitHub Desktop.
Save ashwani-pandey/14c1570245a2947ef053 to your computer and use it in GitHub Desktop.
wrong & right approach
cout.precision(2);
cout<<fixed;
cout<<ans/100<<"$"<<endl;;
string res;
// ans was the variable containg the sum in cents
if(ans%100 !=0)
res = to_string(ans/100) + "." + to_string(ans%100) + "$";
else
res = to_string(ans/100) + ".00$";
cout<<res;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment