In pset7 I am asked to

format price to at least two decimal places but no more than four decimal places.

Could someone please clarify? Should the exact number of decimal places be hardcoded, or should the program calculate the number of decimal places automatically (depending on the number of non-zero decimal digits in the lookup return, for example)?

2 Answers 2


The staff's implementation of Quote appears to display the price of each stock with a hardcoded two decimal places. So hardcoding two decimal places should be okay, although it appears the choice is up to you.

I verified the above by downloading a current CSV file from Yahoo for the GOOG stock, in which the price was listed as $502.3401. I then checked the price with the staff's implementation of Quote, where it was displayed as $502.34. I also checked a number of other stock prices via the the staff's website, and they were all displayed with two decimal places.


Yo can do the calculations directly with the prices you get from lookup, whatever decimals they have, and store the results in the database without worrying about the decimals.

What that means is format the price to display it via html to the web page. So they look all uniform with the same decimal places when the page is loaded.

And the specification is very clear, you can format the prices with at least two decimals but no more than four, you have to do it even if they are zeros. You can displey the price with 2, 3, or 4 decimals, its your choice, and any of the three is correct.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .