Hi everyone,

Please check my code below and tell me that why double stores number upto 3 decimal places ?

#include <iostream>

using namespace std;

int main()
    double dNo;
    dNo = 363.430965;

    cout<<"double no : " <<dNo <<endl;
    //cout only outputs dNo value upto 
    //3 decimal places

    return 0;

Actually i working on assignment in which i need to get number upto different decimal places say 3, 4 etc. But in above case it only store that number upto 3 decimal places and also rounds it off.

How can i store decimal number upto 5, 6 or greater decimal places in double ???

Kindly give me the solution and explain this issue in detail. Thanks !


Edited by new_developer

1 Year
Discussion Span
Last Post by rproffitt
Featured Replies
  • From what I did in C and C++, the data types are the same. Since you only get so many decimal digits in each floating point representations you choose which fits your needs. If you feel you need formatted output, there's still printf() and other ideas at http://stackoverflow.com/questions/15106102/how-to-use-c-stdostream-with-printf-like-formatting Read More

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.