Focal Point
TRUNCATING DECIMALS

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/2911016742

September 19, 2007, 11:07 AM
WFLurker
TRUNCATING DECIMALS
I'm stuck on how to truncate decimals in Webfocus.

I want to truncate for example:

3456.7891 to 3456.7 * I don't want to round off to 3456.8

I don't think there is a trunc command in webfocus


WF 8105M
- Portal, Dashboard
- Rcaster, Data Migrator
- Windows 2012 Client Server
- Dev/App Studio 8105
- Data: SQL, Oracle, Neteeza,MVS
September 19, 2007, 11:16 AM
Glenda
Here's a post with several ways to truncate.

Truncating


Glenda

In FOCUS Since 1990
Production 8.2 Windows
September 19, 2007, 11:47 AM
Prarie
oh too funny

( we need a smiley for head spinning out of control)


In Focus since 1993. WebFOCUS 7.7.03 Win 2003
Sorry guys. I never professed to be a teacher. I was just giving another example of how it could be accomplished. I guess I should have broken it out for those that like to see the fields built one at a time.

Maybe this helps:

DEFINE FILE CAR
TAX/D12.4 = .08125;
SALESTAX/D12.4 = RETAIL_COST * TAX;
-*MULTIPLY SALESTAX BY 100 AND CONVERT TO ALPHA
FTOA_SALESTAX/A14 = FTOA(SALESTAX*100, '(D12.2)', 'A14');
-*FIND THE POSITION OF THE DECIMAL
POSIT_DECIMAL/I2 = POSIT(FTOA_SALESTAX, 14, '.', 1, 'I2');
-*USE SUBSTR TO KEEP EVERYTHING TO THE LEFT OF THE DECIMAL
SUBSTR_SALESTAX/A14 = SUBSTR(14, FTOA_SALESTAX, 1, POSIT_DECIMAL-1, 14, 'A14');
-*REMOVE THE COMMAS
STRIP_SALESTAX/A14 = STRIP(14,SUBSTR_SALESTAX, ',', 'A14');
-*CONVERT BACK TO NUMERIC AND DEVIDE BY 100
TRUNC_SALESTAX/D12.2 = EDIT(STRIP_SALESTAX)/100;
END

TABLE FILE CAR
PRINT
RETAIL_COST
TAX
SALESTAX
TRUNC_SALESTAX
COMPUTE DRIVEOUT/D12.2 = RETAIL_COST + TRUNC_SALESTAX;
ON TABLE PCHOLD FORMAT EXL2K
END
-EXIT


Glenda

In FOCUS Since 1990
Production 8.2 Windows
Thanks Glenda that was helpful!!!

That a lot of steps to truncate something thou...


WF 8105M
- Portal, Dashboard
- Rcaster, Data Migrator
- Windows 2012 Client Server
- Dev/App Studio 8105
- Data: SQL, Oracle, Neteeza,MVS
Try:

DEFINE FILE CAR
INVAL/D12.4 WITH CAR = 3456.7891 ;
MYT/D12.4 = INT(INVAL*10)/10 ;
END
TABLE FILE CAR
PRINT INVAL MYT
IF RECORDLIMIT EQ 1
END


IBI Development
Nice and clean. Works with
MYT/D12.1 = INT(INVAL*10)/10 ; 
as well.


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
No Glenda...that's a lot of nice stuff. Smiler


In Focus since 1993. WebFOCUS 7.7.03 Win 2003
Francis even better!!!


WF 8105M
- Portal, Dashboard
- Rcaster, Data Migrator
- Windows 2012 Client Server
- Dev/App Studio 8105
- Data: SQL, Oracle, Neteeza,MVS
This is Edward's glory, not mine Smiler


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
Ok guys.

Gotta another question.

How would you truncate the other way around.

3456.7891 to .7891 ???


WF 8105M
- Portal, Dashboard
- Rcaster, Data Migrator
- Windows 2012 Client Server
- Dev/App Studio 8105
- Data: SQL, Oracle, Neteeza,MVS
How about
DEFINE FILE CAR
VAL1/D12.4 WITH CAR = 3456.7891 ;
VAL2/D12 = INT(VAL1);
VAL3/D12.4 = VAL1 - VAL2;
END
TABLE FILE CAR
PRINT VAL1 VAL2 VAL3
IF RECORDLIMIT EQ 1
END



Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
OK figured it out.

Is there another shortcut beside this method

PARTIAL/A19 = FTOA(SHARES, '(D15.4)', 'A19');
PARTIAL1/A19 = EDIT(PARTIAL,'$$$$$$$$$$$$$99999');
PARTIAL2/D15.4 = EDIT(PARTIAL1);


WF 8105M
- Portal, Dashboard
- Rcaster, Data Migrator
- Windows 2012 Client Server
- Dev/App Studio 8105
- Data: SQL, Oracle, Neteeza,MVS
How about DMOD

VAL1/D12.4 WITH CAR=3456.7891;
VAL2/D2.4  = DMOD(VAL1, 1, VAL2);
END





Frank

prod: WF 7.6.10 platform Windows,
databases: msSQL2000, msSQL2005, RMS, Oracle, Sybase,IE7
test: WF 7.6.10 on the same platform and databases,IE7

Althought the solution Glenda posted works I think it is far to complex.
The available formats give you the posibility to do this in a more mathematical way.

And just to show you the difference I would suggest to rus this small program and see ...


DEFINE FILE CAR
VAL1/D12.5=1234.5678;
VALUPDEC/D12.2=VAL1;
VALUPPACK/P12.2=VAL1;
VALDOWNDEC/D12.2=VAL1-.005;
VALDOWNPACK/P12.2=VAL1-.005;
END
TABLE FILE CAR
PRINT
 COUNTRY 
 VAL1
 VAL1/D12.2
 VALUPDEC
 VALUPDEC/D12.5
 VALUPPACK
 VALUPPACK/D12.5
 VALDOWNDEC
 VALDOWNDEC/D12.5
 VALDOWNPACK
 VALDOWNPACK/D12.5
ON TABLE SET PAGE-NUM OFF
ON TABLE COLUMN-TOTAL
END


And suppose you have a negativ number that should be rounded up or down...would you use Glenda's solution?

BTW please update your signature....!




Frank

prod: WF 7.6.10 platform Windows,
databases: msSQL2000, msSQL2005, RMS, Oracle, Sybase,IE7
test: WF 7.6.10 on the same platform and databases,IE7

I agree with Frank - there are a lot of ways to do this, but using the 'P' format has been my preferred method because of it's simplicity - no functions and very simple format redefinition (which can be done without a DEFINE in many cases.


Regards,

Darin



In FOCUS since 1991
WF Server: 7.7.04 on Linux and Z/OS, ReportCaster, Self-Service, MRE, Java, Flex
Data: DB2/UDB, Adabas, SQL Server Output: HTML,PDF,EXL2K/07, PS, AHTML, Flex
WF Client: 77 on Linux w/Tomcat