Printing this floating point format
===

![Required format][1]

Observe the above image, the remaining loan amount being displayed in a pretty unique way. It is basically a floating point value. When it is having no floating precision it is displayed as `$3000` when the decimal part has 4 digits 2 floating points are displayed. But when the decimal part has only 3 digits the 3 digit precision is used for floating points. Is this possible to display using only format specifiers?? I tried many combinations of `%X.Yf` but nothing worked. Any ideas?


  [1]: http://i.stack.imgur.com/baDXM.png