jrl@images1.Waterloo.NCR.COM (john Latala) (06/12/90)
One feature that I wish my HP28s did have was a way to do formatted output. It's a real pain when you're trying to display some numbers in a 'nice' way. It can be done eventually, with enough pushing and popping and setting the decimal point to the right number of places and a couple of ->STR and ->STR operations. But it does get a little bit cumbersome. How about a format command that takes a number and a format string from the stack and returns a string which is that number in that format. An unformat command that does the reverse would be nice, but not really needed. Initially I was thinking of something like the BASIC 'USING' clause: "#####.##" 123.456 FORMAT would return: " 123.47" The order of the arguments for the FORMAT command could even be optional, as long as it's a number and a string the usage can be figured out. It would be nice if it worked for any type (except string): (123.45, -234.45) "(####.##, ####.##)" FORMAT would return: "( 123.34, -234.45)" The format control string should have features to let it handle the usual 'formatting' features: - leading blank, "0" or any other character fill - leading zero suppression - variable width output (normal number to string with STD fmt) - various bases - floating minus sign - floating dollar sign are just a quick list of possible nice features. -- john.Latala@Waterloo.NCR.COM
jdg@hpqtdla.HP.COM (James Gentles) (06/14/90)
Your formatter sounds very good, how about a simpler idea if you havent thought of it already. When you try to get a 'nice' output you can set the 28's MODE to STD,FIX etc for the best results but that means that all output adopts that format. The following simple program allows you to "FIX" a number to a string in any format, whilst the 28 remains in the format it started in. NFMT (short for number format) << RCLF 3 ROLLD EVAL ->STR SWAP STOF >> For example (28 in STD mode) Stack on entry: 2: 1.8888888888 1: <<4 FIX>> NFMT Stack on exit: 1: "1.8888" You can put anything in the program in level 1 of the stack, DEC or OCT for example. Granted this system is a lot simpler that an all encompasing formatter, but it should improve your output Regards James --------------------------------------------------------------------- I have no professional connection with Hewlett-Packard's calculator operations other than as a user of their products. --------------------------------------------------------------------- Opinions expressed are my own, and are not intended to be an official statement by Hewlett-Packard Company --------------------------------------------------------------------- Name: James Gentles GM4WZP Organization: Hewlett-Packard Queensferry Telecomunications Division Email: jdg@hpqtdla.hpsqf.hp.com hp-sdd Address: Station Road, South Queensferry, West Lothian, Scotland ---------------------------------------------------------------------