Re: [Dev-C++] floating point numbers
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Martin D. <nex...@qu...> - 2005-08-14 08:03:20
|
P.Lane wrote:
>Hello, I am new to programming and to c++ and Dev-CPP. I have been
>experimenting with numbers and can't figure this one out. Here is the
>code the I am using:
>
>#include<iostream>
>using namespace std;
>int main ()
>{
> int a;
> float b;
> double c;
> long double d;
> cout << " Enter a number: ";
> cin >> d;
> c=d;
> b=d;
> a=d;
> cout << d << endl << c << endl << b << endl << a << endl;
> return 0;
>}
>Here is the result with the number 123456789.123456789:
>1.23457e+008
>1.23457e+008
>1.23457e+008
>123456789
>Now from what I have read, a long double should be good up to 19
>digits, a long up to 15, and a float up to 7. Why does the long double
>return 1.23457e+008, instead of the entered value of
>123456789.123456789, which is only 18 digits long?
>
>
That output is right. Standard setting for floating point values bigger
than 10^6 is scientific notation with first 6 digits. Try tampering with
output formating mathods of std::ostream.
Happy coding,
next_ghost
|