Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem using "long double" data type

Status
Not open for further replies.

unirams

Programmer
Dec 25, 2001
20
IN
Hi,

Anyone help me to find the control string for long double. I want to print the number as it is.
I wrote the following program

main()
{
long double d;
double d1;
d1 = (double)(double)999/(double)1000;
d=(double)(123456789012345+d1);
printf("\nd=%Lf\n",d);
}

For the above program, i am expecting the following result,
123456789012345.999

But i am getting the following output.
d=123456789012346.000000

What is the problem and how i will get the expected output. Please clarify. Thanks in advance.

Regards,
Ram
 
Change the line...
d=(double)(123456789012345+d1);

to...
d=(double)(123456789012345.+d1);
or even...
d = 123456789012345. + d1;

Does that work??
Ankan.

Please do correct me if I am wrong. s-)
 
Change the line...
d=(double)(123456789012345+d1);

to...
d=(double)(123456789012345.+d1);
or even...
d = 123456789012345. + d1;

Does that work??
Ankan.

Please do correct me if I am wrong. s-)
 
Hi,

Thanks for your response. But the code below is working fine now.

d = 123456789012345. + (long double)d1;

Thanks and regards,
Ram
 
Hey use like this,

d = 123456789012345.0l + d1;

use a l / L following the double number, when you want to use a long double number.

Maniraja S.
 
Hi Maniraja,

Still it is not working. I have found the solution. Please my previous response to ankan.

Thanks
Ram
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top