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.
>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.