Let's say I want to write a function that does the following:
Given a number N,
when N is rounded to D1 digits
does the result include more than D2 decimal places, not counting trailing zeroes?
For example, say N is .01001, D1 is 4, and D2 is 2. The question becomes, does .0100 include more than 2 decimal places, not counting trailing zeroes? And the answer is "no". But if N was .00101, the answer would be "yes".
I'm looking for an efficient way to do this using standard C library functions, taking into account the limitations of floating-point numbers.
An example of my intended usage: show a number using four digits if necessary, but otherwise show it using two digits.
(This is not a homework question -- this is a result of being a professional programmer who didn't do these kinds of homework questions when he was a student.)