473,651 Members | 2,792 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.141592266 2266;
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.141592266 2266;
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.141592266 2266;
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.14159 22662266;
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 6210

"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::setprecisi on () 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.141592266 2266;
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.141592266 2266;
I_float = I_double;
I_int = I_float;
etc, then printing it and you should then notice better accuracy....


l_float = 33333.141592266 2266;
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.141592266 2266;
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.14159 22662266;
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
4337
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 0.0103 --> 4 0.00103 --> 5 0.000103 --> 6 0.0000103 --> 7
2
4067
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) for the result. How can I specify the result attributes within a SELECT? Lukas
8
18765
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 instead of _about_ what I want. Taken down to just the part relevant to my question, here's the code, the desired result, and the actual result... double somenumber = round(2453126.7227083333 * 100000.0) / 100000.0; desired: somenumber =...
2
9479
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
2510
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 0.0103 --> 4 0.00103 --> 5 0.000103 --> 6 0.0000103 --> 7
6
4002
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 namespace std; int main () {
7
18565
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 show a specific number of significant digits to the right of the decimal place with a format string? NOT number of decimal places, significant digits. For example;
2
3472
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 displayed.</BLOCKQUOTE> The statement appears here: http://www.cppreference.com/stdio/printf.html Also, what do we mean by the magnitude of a floating point number?
3
1934
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 http://www.hazelwood.k12.mo.us/~grichert/sciweb/phys8.htm): When measuring, there is some uncertainty as to the *exact* value; so, when doing calculations with these measured numbers, one should not present an answer that seems more accurate than the source. For...
0
8352
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8802
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8465
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8579
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7297
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5612
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4283
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2699
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1587
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.