Search
You ask the question of a type conversion: Operating Systems
Obicn
You ask the question of a type conversion
RPGIII younger brother encountered in the conversion of> Wishing a character variable converted into digital type, character variables in the uncertain position of the decimal point.
Example: for the following variables may be value
0.1200
12.1
15.999
...
Are there any good solution?
RPGIII not in the type of conversion like the operation code or function, is it?
RPGIII younger brother encountered in the conversion of> Wishing a character variable converted into digital type, character variables in the uncertain position of the decimal point.
Example: for the following variables may be value
0.1200
12.1
15.999
...
Are there any good solution?
RPGIII not in the type of conversion like the operation code or function, is it?
Span1024 back in :2005-07-14 11:36:28 | 1, guarantees the right alignment characters, what I mean is: Assuming your string is eight, according to your value to be aligned as follows: | Bb0.1200 Bbbb12.1 Bb15.999 2, and then use MOVE operation can be a type conversion. Zuozhenglin back in :2005-07-14 12:56:16 | Span1024: This seems not? | 1. String is left-justified, if converted into the right alignment, is not very convenient 2. String with a decimal point MOVE operation itself does not use the number of variables to the assignment Span1024 back in :2005-07-14 13:50:17 | Not tried, assuming the conclusion is a very bad habit. | Again> Majorz back in :2005-07-14 14:18:11 Upstairs said is correct: | If the original 123 is the character, Move 123 a 4 Movel a b (factor2) 6 (len) 2 (dec) Will be translated into a number of types Result: b = 123.00 Zuozhenglin back in :2005-07-18 09:09:01 | Wu Wu is not ..... ah! | I use the method of transmission of how not to try, because: 1, with a small number of how a string of figures can pass variables from using illegal procedures, error message "Error RPG0907 caused program AAAR3 to stop."; 2, I would like to ask for a string from left to right alignment into alignment with any good alternatives? (Display document in the right alignment except); 3, upstairs cite examples is a special case. Move 123 a 4 / / a = "123" Movel a b (factor2) 6 (len) 2 (dec) / / is the equivalent Zuozhuan value "012300", b natural equivalent of "123.00", but if six is a long string again how like? The results of its b equivalent of "1.23", the natural result is not what we want. If a value equal to the "1.23", the result is illegal exit. Fxf_china back in :2005-07-18 11:41:58 | Asked others not before he wrote a paragraph RPG to expect good method | Rodenmao back in :2005-07-18 13:00:31 | The key issue is a string ".", | Provide an idea: 1, string right alignment; 2, use '.' SCAN W # CHAR I find out the location of the decimal point, J = length - I; 3, stresses the left of the decimal point and the right of the characters put an integer variables W # DEC1; 4, W # DEC1 / J can be. (Using an array realization) Majorz back in :2005-07-18 15:16:28 | [Quote: c592b713e3 = "majorz"] upstairs said is correct: | If the original 123 is the character, Move 123 a 4 Movel a b (factor2) 6 (len) 2 (dec) Will be translated into a ..........[/ quote: c592b713e3] Sorry, you said that this method of data there are problems. Roden back in :2005-07-18 15:39:08 | [Quote: 8e9338f0a6 = "rodenmao"] is the key issue in a string ".", | Provide an idea: 1, string right alignment; 2, use '.' SCAN W # CHAR I find out the location of the decimal point, J = length - I; 3, stresses the left of the decimal point and the right of the characters put an integer variables W # DEC1; 4, W # DEC ..........[/ quote: 8e9338f0a6] I am wrong, the last step to do this deal with: J J = 10 ** (10 J-Power) Majorz back in :2005-07-18 16:34:04 | Henben used a method, let us look at where there are unreasonable requests master correction. | A conversion for you to the data. Which E and the length of F0 to F6 .... A length according to the length determined. C '.' SCAN A C 3 0 21 C * IN21 IFEQ'0 ' C C C SUB 1 C C SUBST A: 1 E 6 C '' SCAN E: C Z 3 0 C SELEC C Z WHEQ 6 C MOVEL E F6 5 C MOVE F6 FX 8 C Z WHEQ 5 C MOVEL E F5 4 C MOVE F5 FX 8 C Z WHEQ 4 C MOVEL E F4 3 C MOVE F4 FX 8 C Z WHEQ 3 C MOVEL E F3 2 C MOVE F3 FX 8 C Z WHEQ 2 C MOVEL E F2 1 C MOVE F2 FX 8 C Z WHEQ 1 C MOVEL E F1 6 C MOVE F1 FX 8 C Z WHEQ 0 C MOVEL E F0 6 C MOVE F0 FX 8 C ENDSL C ADD 2 C C SUBST A: C D 4 C '':'0 'XLATE D D C FX CAT D Y 12 C MOVE Y X 124 C ENDIF C SETON LR X is converted to the value. If we want to rpg4, it will be properly achieved ah addition, the extension of the data Mody lz decimal character, and even never encountered before. Fxf_china back in :2005-07-18 17:37:06 | Cou lively ,^_^, no use SCAN, ashamed | 1, E table definition E STN 50 1 E STN1 50 1 E STN2 50 1 2. C *================================= C * S # STN - STRING TO NUMBER C *================================= C * Input: STN C * Output: W # STNZ C S # STN BEGSR C CLEARSTN1 C CLEARSTN2 C MOVEL'0 'W # 1 STNF ADD50 K C Z-40 C Z-ADD50 L 40 C Z-ADD0 M 40 C DO 50 I 40 C * back starts View C 51 SUB I J 40 C * decimal part C STN, J IFNE * BLANK C STN, J ANDNE '.' C W # STNF ANDEQ'0 ' C ADD 1 M C MOVE STN, J STN1, K C SUB 1 K C ENDIF C * Decimal C STN, J IFEQ '.' C MOVEL'1 'W # STNF C ENDIF C * integral part C STN, J IFNE * BLANK C STN, J ANDNE '.' C W # STNF ANDEQ'1 ' C MOVE STN, J STN2, L C SUB 1 L C ENDIF C ENDDO C CLEARW # STN1 C CLEARW # STN2 C CLEARW # STND C CLEARW # STNE C Z-ADD1 W # STNV C W # STNF IFEQ'0 ' C * There is no decimal point of C MOVEASTN1 W # STN1 50 C MOVE W STN1 W # # 100 STND C Z-ADDW STND W # # 199 STNZ C ELSE C * decimal point of C MOVEASTN1 W # STN1 50 C MOVEASTN2 W # STN2 50 C MOVE W STN1 W # # 100 STND C DO M I C W # W # 10 STNV MULT STNV 100 C ENDDO C W STND DIV W # # # STNZ STNV W C MOVE W # # STN2 W STNE 90 C ADD W # # STNZ 199 STNE W C ENDIF C * C E # STN ENDSR Zuozhenglin back in :2005-07-19 23:03:46 | Thank you for your enthusiastic help, younger brother to carefully read the responses, the following observations: | 1, majorz approach seems to be the problem, if memory does not fail me SCANR operation code found> 2, the method should be able to fxf_china. But it is unable to test at home tomorrow to the company to test. 3, in accordance with your ideas, younger brother also wrote some code. Thinking is: will be an integral part of Zuozhuan to the number of variables, such as length, will inevitably enlarge: 10 (total long string - part of the long integer)-th times are divided by the integer part of it. Zuozhuan part of a minority to the number of variables, such as length, will inevitably enlarge: 10 (the number of) square times, it received divided by the decimal part. Taken together in the desired value. Code are as follows: (tested) C * Input: A C * Output: # A C '.' SCAN A WL 20 30 decimal point position C '' CHEKRA WN 20 31 spaces position C N31 Z-ADD10 WN C * integral part of Digital C * WA: integer; WB: Decimal; WX: integral part of magnification; WY: Decimal some times magnification C * decimal point when there * IN C, 30 IFEQ'1 ' C WL SUB 1 W # L 20 # C W L SUBSTA: 1 P W # A 10 C Z ADD1 WX-100 C # 10 SUB W L WM 30 DO WM C 1 C MULT 10 WX C ENDDO A WA C MOVELW # 100 C DIV WX WA C * C WL ADD 1 WO 30 C SUBSTA: WO W # 10 P B MULT 100 million WY 100 C 110 C MOVELW # B WB 199 C DIV WY WB C * decimal point does not exist, C ELSE C MOVELA W # A C Z ADD1 WX-100 |
