Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to convert a double to long double in C++ style?

In C++, we can use 1ll to convert a number to long long type. Is there a similar way to convert to long double type in C++? If so, what should I multiply the number by? Thank you!

I’ve tried 1.0f, but that’s not what I’m looking for because it lacks precision.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

In C++, to convert a number to long double type, you can simply append an "L" or "l" to the number. This tells the compiler to treat the number as a long double. Here’s how you can do it:

long double myNumber = 1.0L;

By appending "L" or "l" to the number, you ensure that it’s interpreted as a long double literal rather than a double or float. This allows you to maintain precision in calculations involving long double values.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading