×

Good News Everybody!

The new search engine is LIVE!

Please report any problems to david (at) midrange.com.




Here is the prodecure that worked for the current report (I didn't
exhaustively test it). This procedure will format a large number to fit into
a smaller variable (shrink variable size for printing).

The key calc is setting the max value (thanks Jonathan for remembering your
algebra!). It uses exponential notation to calculate a number that is just
bigger than the target and then subtracts the amount that will return all
nines for the right size of the print field. A quick review of some algebra
web pages reveals that any number (except 0) with exponent 0 is defined as
1. This allows the calc to work for zero decimal positions. A negative
exponent for the number ten will have that many decimals in the result
(-1=.1, -2=.01, -3=.001, etc).

For example:
Size of Fld Num of Dec maxValue Calc
%len(field) %decpos(field) (10 ** (length-decPos))-(10 ** (-1 * (decpos)))
1 0 (10**1)-(10**0) =10-1 =9
7 0 (10**7)-(10**0) =10,000,000-1=9,999,999
7 1 (10**6)-(10**-1)=1,000,000-.1=999,999.9
7 4 (10**3)-(10**-4)=1000-.0001 =999.9999
3 3 (10**0)-(10**-3)=1-.001 =.999

Mike Krebs

//--------------------------------------------------
// Procedure name: GetPrintVal
// Purpose: Set print value according to size of field
// Returns: Print value
// Parameter: inValue => Value to check
// Parameter: length => Length of print field
// Parameter: decPos => Decimal positions
//--------------------------------------------------
D GetPrintVal PR 60P10
D inValue 60P10 CONST
D length 5I 0 CONST
D decPos 5I 0 CONST


//--------------------------------------------------
// Procedure name: GetPrintVal
// Purpose: Set print value according to size of field
// Returns: Print value
// Parameter: inValue => Value to check
// Parameter: length => Length of print field
// Parameter: decPos => Decimal positions
//--------------------------------------------------
P GetPrintVal B
D GetPrintVal PI 60P10
D inValue 60P10 CONST
D length 5I 0 CONST
D decPos 5I 0 CONST

// Local fields
D maxValue S 60P10
D minValue S 60P10

/FREE
maxValue = (10 ** (length-decPos))-(10 ** (-1 * (decpos)));
minValue = 0 - maxValue;
if inValue > maxValue;
return maxValue;
EndIf;
if inValue < minValue;
return minValue;
EndIf;
return inValue;

/END-FREE
P GetPrintVal E

Here is an example of how you use it.
D printField s 7 0
D extOHCost s 21 6
D onHand s 9 0
D baseCost s 13 6

/FREE
printField =
GetPrintVal(onHand*baseCost:%len(printField):%decpos(printField));
(or like this)
extOHCost = onHand * baseCost;
printField=
GetPrintVal(extOHCost:%len(printField):%decpos(printField));
/END-FREE


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2026 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.