Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
nidhi.palsule

New User

Joined: 17 Feb 2009
Posts: 9
Location: Pune

 Posted: Wed Mar 31, 2010 5:17 pm    Post subject: Problem in character to Float Bin conversion I am converting a string '9.70000000' to Float Bin (53) using the builtin function FLOAT. My problem is that it gets converted to 9.699999809265137E+00. Can someone please tell me why and provide me a solution to retain the exact value in float?

enrico-sorichetti

Global Moderator

Joined: 14 Mar 2007
Posts: 10457
Location: italy

 Posted: Wed Mar 31, 2010 5:25 pm    Post subject: Reply to: Problem in character to Float Bin conversion by definition floating point values ( as a general case ) will never be exact values
Robert Sample

Global Moderator

Joined: 06 Jun 2008
Posts: 8280
Location: Dubuque, Iowa, USA

 Posted: Wed Mar 31, 2010 5:26 pm    Post subject: Floating point values do not always exactly represent a mathematical value. Obviously, 9.7 is one of those values. The reasons have to do with the way the computer stores numbers and the fact that computers cannot store an infinite number of digits. Unfortunately, there is no way to retain the exact value in floating point. This is one of the drawbacks to dealing with floating point.
enrico-sorichetti

Global Moderator

Joined: 14 Mar 2007
Posts: 10457
Location: italy

 Posted: Wed Mar 31, 2010 5:30 pm    Post subject: Reply to: Problem in character to Float Bin conversion and to add to Robert considerations there are base10 numbers which cannot be represented as base2 numbers ( fractional numbers of course )
nidhi.palsule

New User

Joined: 17 Feb 2009
Posts: 9
Location: Pune

 Posted: Wed Mar 31, 2010 5:45 pm    Post subject: But there are only a few cases where I have faced this problem, only one data record out of millions and that too only once or twice a year. Also when I directly move a character string into a floating point variable, it retains the values, but when I use the function FLOAT to convert the value changes.
Akatsukami

Global Moderator

Joined: 03 Oct 2009
Posts: 1786
Location: Bloomington, IL

 Posted: Wed Mar 31, 2010 8:52 pm    Post subject: Note that some, but not all, decimal numbers can not be accurately represented as floating point. We'd really need to see the usage of the FLOAT function, the source code, the compiler options, and the data (and a few benjamins -- I think that USD 125/hour is an average billing rate for us senior types) to determine exactly what is happening in each case.
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics Invalid XML character while producing... nikhil.bhole IBM Tools 4 Tue Mar 20, 2018 1:24 am Conversion of DLI update Jobs as BMP ... Gopinath Shanmugam IMS DB/DC 3 Wed Dec 20, 2017 12:02 pm Conversion of UTF-8 to EBCDIC muralikrishnan_new COBOL Programming 1 Tue Nov 21, 2017 5:33 pm Mainframe Blocks to Tracks conversion upendrasri JCL & VSAM 1 Sat Nov 18, 2017 10:52 am Having a problem FTP'ng to the MF pahiker All Other Mainframe Topics 2 Fri Nov 10, 2017 8:20 pm

 © 2003-2017 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us