From: "Olin Lathrop" > Jinx wrote: >> I would like to cater for any format of i/p the user chooses, so >> the only significant character is the "." (or lack thereof, implying >> an integer). ie 0022, 022, 22, 22.0, 22.00 must all be interpreted >> by the PIC as plain 22. I realise that the more latitude I give the >> user, the more comprehensive the interpreter needs to be, but I'm >> prepared to go the extra mile for the sake of user-friendliness > > This is really not hard if you break it into two algorithms, one before > the > point and one after. Before the point initialize the value to 0. For > each > digit, multiply the current value by 10, then add the digit. After the > point init a scale factor to .1. For each digit, multiply the digit value > by the scale factor, add that into the accumulated value, then multiply > the > scale factor by .1. As shown by my previous post, this is really not necessary. You can just scan the value from left to right, pretending it is an integer, but remembering where the decimal point is. When you are done you simply multiply by 10 as many times as needed to scale the final result to two decimal places. Bob Ammerman -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist