473,503 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Significant digits

pw
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;
}
Jul 19 '05 #1
2 6202

"pw" <no**************@bigpond.net> wrote in message
news:cS****************@news-server.bigpond.net.au...
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.
Jul 19 '05 #2
On Thu, 26 Jun 2003 04:43:52 GMT, "pw" <no**************@bigpond.net>
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;
}

Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

29
4310
by: mrstephengross | last post by:
Hi all... How can I find out the number of significant digits (to the right of the decimal place, that is) in a double? At least, I *think* that's what I'm asking for. For instance: 0.103 --> 3...
2
4061
by: Lukas Bradley | last post by:
Using MySQL 4.0.12, is there a way to specify significant digits for a mathematical operation within a SELECT? In other words, the query "select 5/213" defaults to two significant digits (0.02)...
8
18736
by: David Corby | last post by:
Hi everybody, I've got a problem. I'm trying to round a double to a particular number of significant digits, in this case 5, but I can't figure out a way around getting _exactly_ what I want...
2
9468
by: Andy | last post by:
Could anyone tell me how to round off a number to certain significant figures using C++? For example, how to round off a number 12567 to 13000 (2 significant figures)?
3
2485
by: mrstephengross | last post by:
Hi all... How can I find out the number of significant digits (to the right of the decimal place, that is) in a double? At least, I *think* that's what I'm asking for. For instance: 0.103 -->...
6
3997
by: Jonny | last post by:
If you run the following code , you will get 1.12346e07 as the output. What do I need to do if you want all the significant digits output, like 1.123456789e07? #include<iostream> using...
7
18558
by: Michael Howes | last post by:
MSDN documentation for format strings seems ambiguous. It's says things like "significant digits or number of decimal places" all over the place. Well those two things are different. How do I...
2
3458
by: Mukesh_Singh_Nick | last post by:
What is meant by the "most significant digits" in the following statement? <BLOCKQUOTE> With %g and %G, the precision modifier determines the maximum number of significant digits...
3
1925
by: Ethan Furman | last post by:
Hey all. My thanks to all who have responded so far with my other questions. It is much appreciated. Some background on what I'm doing (a good explanation can be found at...
0
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7274
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7453
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5005
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4670
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3162
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3151
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
732
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
377
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.