Decimal places

This is a discussion on Decimal places within the Windows Programming forums, part of the Platform Specific Boards category; Hello
I use sprintf_s() to convert numbers to strings however I have a problem with decimal places. What do I ...

Decimal places

Hello

I use sprintf_s() to convert numbers to strings however I have a problem with decimal places. What do I do if I dont know in advance how many decimal places will a number have and I want to show decimal places only if there are any.

2045 / 756 I have no idea how many decimal places will the answer have. What do I do to find out?

If I use only

Code:

ValueX = 2045 / 756;
sprintf_s(lpText, "x = %.*f", 2, ValueX);

That will end up with two decimal places even if they are both zeroes... In this case it will work but what if I had 9 / 3...

Constants (in float.h) like DBL_DIG tell you how many significant digits a floating point type has.

You might think you havefloat pi = 3.1415926535897932384626433832795;
But since FLT_DIG on most systems is 6, it's only the red part which has any real significance. The rest (however accurate it may appear) is just noise.

Constants (in float.h) like DBL_DIG tell you how many significant digits a floating point type has.

You might think you havefloat pi = 3.1415926535897932384626433832795;
But since FLT_DIG on most systems is 6, it's only the red part which has any real significance. The rest (however accurate it may appear) is just noise.

It only specifies how many digits are guaranteed to be exact, the rest might be accurate too, depending on the calculation.

Constants (in float.h) like DBL_DIG tell you how many significant digits a floating point type has.

You might think you havefloat pi = 3.1415926535897932384626433832795;
But since FLT_DIG on most systems is 6, it's only the red part which has any real significance. The rest (however accurate it may appear) is just noise.

On x87 systems, some constants, like pi, are encoded in the FPU itself to 82 bits, adn rounded at execution time according to the currently active rounding model to 80 bits. All FPU operations are 80 bit internally, then converted to single double or extended precision when it is transferred to memory.

Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.