Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Significant digits

Reply
Thread Tools

Significant digits

 
 
pw
Guest
Posts: n/a
 
      06-26-2003
Running this on MSWin2000 PC, I show 6 only digits for float and double.
i.e. l_float and l_double show 33333.1 (6 only digits).

Is it possible to increase/alter this?

[code]
// Test ints, floats and doubles
#include <iostream>
using namespace std;

int main()
{
int l_int;
float l_float;
double l_double;

l_int = 33333.1415922662266;
l_float = l_int;
l_double = l_int;

cout << "Define int: " << l_int << endl;
cout << "l_int: " << l_int << endl;
cout << "l_float: " << l_float << endl;
cout << "l_double: " << l_double << endl;
cout << endl;

l_float = 33333.1415922662266;
l_int = l_float;
l_double = l_float;

cout << "Define float: " << l_float << endl;
cout << "l_int: " << l_int << endl;
cout << "l_float: " << l_float << endl;
cout << "l_double: " << l_double << endl;
cout << endl;

l_double = 33333.1415922662266;
l_int = l_double;
l_float = l_double;

cout << "Define double: " << l_double << endl;
cout << "l_int: " << l_int << endl;
cout << "l_float: " << l_float << endl;
cout << "l_double: " << l_double << endl;
cout << endl;

l_double = 333333333.1415922662266;
l_int = l_double;
l_float = l_double;

cout << "Define double: " << l_double << endl;
cout << "l_int: " << l_int << endl;
cout << "l_float: " << l_float << endl;
cout << "l_double: " << l_double << endl;
cout << endl;

return 0;
}


 
Reply With Quote
 
 
 
 
Josephine Schafer
Guest
Posts: n/a
 
      06-26-2003

"pw" <(E-Mail Removed)> wrote in message
news:cSuKa.323$(E-Mail Removed)...
> Running this on MSWin2000 PC, I show 6 only digits for float and double.
> i.e. l_float and l_double show 33333.1 (6 only digits).
>
> Is it possible to increase/alter this?
>

Sure. std::setprecision () is what you are looking for.


 
Reply With Quote
 
 
 
 
John H. Guillory
Guest
Posts: n/a
 
      06-29-2003
On Thu, 26 Jun 2003 04:43:52 GMT, "pw" <(E-Mail Removed)>
wrote:

>Running this on MSWin2000 PC, I show 6 only digits for float and double.
>i.e. l_float and l_double show 33333.1 (6 only digits).
>
>Is it possible to increase/alter this?
>
>[code]
>// Test ints, floats and doubles
>#include <iostream>
>using namespace std;
>
>int main()
>{
> int l_int;
> float l_float;
> double l_double;
>
> l_int = 33333.1415922662266;
> l_float = l_int;
> l_double = l_int;
>
> cout << "Define int: " << l_int << endl;
> cout << "l_int: " << l_int << endl;
> cout << "l_float: " << l_float << endl;
> cout << "l_double: " << l_double << endl;
> cout << endl;




If you even get the .1, your compiler must be whacked out.... Consider
what you are doing here.... Storing a decimal number into an int
(I_int), results in I_int equal to 33333. I_float then gets that
value stored into it. (33333). I_double, then gets the 33333 stored
into it.... Consider changing it to:

I_double = 33333.1415922662266;
I_float = I_double;
I_int = I_float;


etc, then printing it and you should then notice better accuracy....


>
> l_float = 33333.1415922662266;
> l_int = l_float;
> l_double = l_float;
>
> cout << "Define float: " << l_float << endl;
> cout << "l_int: " << l_int << endl;
> cout << "l_float: " << l_float << endl;
> cout << "l_double: " << l_double << endl;
> cout << endl;
>
> l_double = 33333.1415922662266;
> l_int = l_double;
> l_float = l_double;
>
> cout << "Define double: " << l_double << endl;
> cout << "l_int: " << l_int << endl;
> cout << "l_float: " << l_float << endl;
> cout << "l_double: " << l_double << endl;
> cout << endl;
>
> l_double = 333333333.1415922662266;
> l_int = l_double;
> l_float = l_double;
>
> cout << "Define double: " << l_double << endl;
> cout << "l_int: " << l_int << endl;
> cout << "l_float: " << l_float << endl;
> cout << "l_double: " << l_double << endl;
> cout << endl;
>
> return 0;
>}
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
most significant and less significant address a01lida VHDL 2 11-16-2008 12:28 PM
Significant Digits (Significant Figures) SMH Javascript 0 01-07-2007 09:52 AM
converted long to double lost significant digits... Jonny C++ 6 10-10-2005 05:16 PM
How to detect a double's significant digits mrstephengross Python 29 05-23-2005 02:50 AM
Round float to X significant digits David Corby C++ 8 05-02-2004 05:34 AM



Advertisments