|
>My colleague wants to code a program to generate nagative values in
>brackets and not with a minus sign nor with a CR sign. Problem is that
>she wants the leading bracket to float like the $ sign.
>Eg.
> (89.00)
> (2,341.00)
I use this method to output and retrieve numerics from html entry fields.
It's a little cludgy, but it works and might be just what you need:
The screen field is alpha, so you may need to do a little extra editing if it
is input capable to keep them from entering anything
other than 0-9, ( ) , . and $. the sub-procedure "str2flt is a standard "C"
routine that converts an alpha string to a floating
point decimal.
to output to screen:
DDS:
A EDITFLD 12A B 2 2
........
RPG4:
To output to screen:
* if negative, append parenteses before and after edited numeric.
C IF NUMFLD < 0
C EVAL EDITFLD = '(' + %trim(%editc(NUMFLD:'1')) + ')'
C ELSE
C EVAL EDITFLD = %trim(%editc(NUMFLD:'1'))
C END
If you need to read from screen:
D Str2Flt Pr 8F ExtProc('cvtefnd')
D Str * Value
D StrLen 10U 0 Value
D Mask 3 Const
D FltResult S 8F
....
* check if field is numeric.
==
C '(' CHECK EDITFLD POS 10
* replace parentheses with zeroes.
C '()':'00' XLATE EDITFLD EDITFLD
* convert alpha string to floating point, then to numeric
C Eval FltResult = Str2Flt( %Addr(EDITFLD) :
C %Len(%trimr(EDITFLD)) :
C '$,.' )
C Eval NUMFLD = FltResult
C END
* if value had parentheses, make negative.
C IF *IN10 = *on
C Z-SUB NUMFLD NUMFLD
C END
You will need to compile this program with parameter "BNDDIR(QC2LE)".
Hope this helps a little,
Rick
+---
| This is the Midrange System Mailing List!
| To submit a new message, send your mail to MIDRANGE-L@midrange.com.
| To unsubscribe from this list send email to MIDRANGE-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.