May 2002
Beginner
704 pages
16h 37m
English
This final example uses split and patterns. The script in Listing 5.3 is a bit of an enhancement to the stock script on Day 3—the script where you typed in the beginning and ending prices of a stock, and it calculated the return on your investment. In that version of the script, you weren't allowed to enter stocks in the old-style format of fractional prices (14 5/8); we tested for that using regular expressions and printed an error.
This script isn't really a stock script; instead it's more of a price-checking and fixing script. It allows prices in plain numeric format. It checks for nondecimal characters and prints an error, as before. But if you enter in a price in a fractional format, it converts ...