0

I'll try to get this as simple as possible. The problem is fairly simple.

long double a=100000000;
cout<<a;

Well, the output this shows is "1e+08"

I do not want the output to be in exponential form. Rather, I want it to be printed as "100000000".

What shall I do?

Thnaks in advance.

4
Contributors
11
Replies
12
Views
7 Years
Discussion Span
Last Post by s_sridhar
Featured Replies
0

Use std::fixed.

cout << std::fixed << a;

Hi...Thanks for a response.

But, I am getting the following errors:-

Type qualifier 'std' must be a struct or class anme in function main()

Statement misisng in function main()

The errors occur when the program is as follows:-

#include<iostream.h>
#include<conio.h>

void main()

{
	 long double a=100000000.0;
 cout<<std::fixed<<a;
 getch();
}
0

Which compiler are you using?

#include<iostream>
using namespace std;

int main()
{
  long double a=100000000.0;
  cout<<std::fixed<<a;
  return 0;
 }

Use CodeBlocks compiler.

0

I'm using Turbo C++ 4.5

From where can I download codeblocks compiler?

0

I'm using Turbo C++ 4.5

From where can I download codeblocks compiler?

CodeBlocks

Include iomanip header file and use setiosflags(ios::fixed,ios::adjustfield) manipulator.

Mark this thread as Solved if you get solution.

0

"cout" doesn't support any specific formatting.

cout supports a lot of formatting options, and you can add more. It is a very flexible design, much more flexible than printf. But the design is very verbose and convoluted compared to printf.

You can use printf defined under stdio. Use a corresponding qualifier.

I agree. For most of the formatting jobs that printf can do, it is shorter and probably faster that cout. Which makes more sense here when printing fixed format with no precision?

#include <iostream>
#include <iomanip>
#include <cstdio>

using namespace std;

int main()
{
    long double value = 100000000.0;

    // chained modifiers on cout
    cout << fixed << setprecision(0) << value << '\n';

    // printf with a format string
    printf("%.0f\n", value);
}

The cout line is a little over twice as long, and it is not as obvious what the output will look like by skimming the code. I think formatting macros embedded in an output string are easier to figure out, but not having to type all of that extra junk is a big win.

0

Thanks for help everyone. Well, the problem si that I don't know how a printf function works. A link to guide on using printf would be highly appreciated.

2

Ok, Ok, Everyone screwed me. But, I felt that printf would be easier to format.

Votes + Comments
"printf" is often easier. unfortunately, that the way you worded your response was incorrect.
Those guys just can't handle different opinions.
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.