Find the answer to your Linux question:
Results 1 to 5 of 5
I am dealing with money and I don't want it to show $.1, I'd rather it show $.10 Is there a way to change this in C++?...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2010
    Posts
    32

    Force a floating point to show more 0s


    I am dealing with money and I don't want it to show $.1, I'd rather it show $.10

    Is there a way to change this in C++?

  2. #2
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    Sure.
    Show us your printing code. cout, printf, ...?
    Debian GNU/Linux -- You know you want it.

  3. #3
    Just Joined!
    Join Date
    Aug 2010
    Posts
    32
    // b5.cpp : Defines the entry point for the console application.
    //

    #include "stdafx.h"
    #include <iostream>
    using namespace std;

    int _tmain(int argc, _TCHAR* argv[])
    {

    float late,price;
    cout << "Enter the number of days late: ";
    cin >> late;

    if (late>3) {
    price=(.15+(late-3)*.10);
    } else {
    price=.05*late;
    }

    cout << "Your late fee is $" << price <<endl;

    system ("pause");
    return 0;
    }


    I'm new so yes i8t's simple >_<

  4. #4
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    Debian GNU/Linux -- You know you want it.

  5. #5
    Just Joined!
    Join Date
    Aug 2010
    Posts
    32
    Thanks a bunch

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •