How to change numerical values from scientific notation to normal system (:P) in C++ if i used a float or double variable
Cuz i want decimals tthats why i used float but now its giving me the answer of my program in scientific notation ?

or is there any way to round off the decimals to the nearest three or any other value ?

Welcome aboard. With regards to your variable, you may want to use 'double'. As for the formating of your number to a specific decimal point and to make the digits show, you use smething like this:

cout<<fixed<<showpoint<<setprecision(2)<<number<<endl;

The above will print the variable number (a double type) to two decimal places and forces the compiler not to show it in scientific notation. Hope this helps.

Hey how can i convert scientific notations ??

if i use float in my program

is it possible to change it ????

#include <iostream>
using namespace std;

int main()
	{	
		char againKel;
		cout << "\n================================ Kelvin Converter ==============================\n\n" ;		
		
		
		do {
		cout << "Enter °K (Kelvin) degree to convert :";
		float kTemp2Conv; // Kelvin Temperature to Convert
		
		
		
			if (cin >> kTemp2Conv) {
				
				
				float kCelsius = kTemp2Conv - 273.15;
				float kFahrenheit = (kTemp2Conv * 1.8) - 459.67;
				float kRankine = kTemp2Conv * 1.8;
				
				
				cout << "\nAnswer: " << kTemp2Conv << " K (Kelvin) in Celsius scale = " << kCelsius;
				cout << "\nAnswer: " << kTemp2Conv << " K (Kelvin) in Fahrenheit scale = " << kFahrenheit; 
				cout << "\nAnswer: " << kTemp2Conv << " K (Kelvin) in Rankine scale = " << kRankine;
				cout << "\n\n";
			}
			else {
				cout << "\nINVALID INPUT !";
				cout << "\nPlease enter numerical values.\n";
			}
			cin.clear();
			cin.ignore(100, '\n');
			cout << "\nDo you want to convert temperature again ?";
			cout << "\nEnter Y for yes, N for no.";
			cout << "\nEntering wrong option other than Y/N will result in getting back to \nConvert Temprature menu.";
			cout << "\n[y]/[n]:";
			cin >> againKel;
				
		} while (againKel == 'y'|| againKel == 'Y');
	}

run the program and enter 273.15

and then look at the answer of celsius

273.15 K= 0 C

but it shows me a very long answer

-6.10352e-06 this is what i Got now

is there any way to convert the scientific digit

Why did you start a new thread on the same topic? Please continue with the original thread.

Welcome aboard. With regards to your variable, you may want to use 'double'. As for the formating of your number to a specific decimal point and to make the digits show, you use smething like this:

cout<<fixed<<showpoint<<setprecision(2)<<number<<endl;

The above will print the variable number (a double type) to two decimal places and forces the compiler not to show it in scientific notation. Hope this helps. hhhmmm.....why are double posting the same question??? Read the rules about the forum. You only need to ask your questions once.

hey, i made this random number generator and the highest number it can generate is 700 octillion. but every time it creates a number, its in scientific notation. Is there any scientific notation to integer converter in C++?

include<ctime>
#include<iostream>
using namespace std;
int main (char argc)
{
srand((unsigned)time(0));
double n27 = rand();
double lowest=1, highest=7e+27;
double range=(highest-lowest)+1;
n27 = lowest+int(range*rand()/(RAND_MAX + 1.0));
cout << n27 << endl;
system("pause");
}

Hi thecoolman5,

First off, I think you should always create your own thread rather than asking questions in a thread created by someone else.

However, welcome!

The way to convert from scientific notation to regular integers is done using the setf member function. For instance, by setting the formatting flags, you give yourself a host of options with how to display the numeric data. If you set the ios::fixed flag, you can make sure that floating-point numbers are not written in e-notation. If you set the ios::scientific flag, you can make sure they are written in e-notation.

Here's a small example of setting the ios::fixed flag to not display floating-point numbers in scientific notation.

#include <iostream>

int main()
{
    double pi = 384790124379273489274923740928743027492735e33;

    std::cout.setf(std::ios::fixed);
    std::cout << pi << std::endl;

    return 0;
}

ok. I tried that code above in my random number generating program and now it creates the exact same number every time I run it. Is that because 700 octillion is too big for C++ to handle or what?

ok. I tried that code above in my random number generating program and now it creates the exact same number every time I run it. Is that because 700 octillion is too big for C++ to handle or what?

Hi thecoolman5,

I believe it is too big a number to hold in the standard C++ data types.

http://msdn.microsoft.com/en-us/library/s3f49ktz%28v=vs.80%29.aspx

However, you could always create a BigInteger class similar to Java's.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.