Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Problem in character to Float Bin conversion

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> PL/I & Assembler
View previous topic :: :: View next topic  
Author Message
nidhi.palsule

New User


Joined: 17 Feb 2009
Posts: 9
Location: Pune

PostPosted: Wed Mar 31, 2010 5:17 pm    Post subject: Problem in character to Float Bin conversion
Reply with quote

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?
Back to top
View user's profile Send private message

enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10211
Location: italy

PostPosted: Wed Mar 31, 2010 5:25 pm    Post subject: Reply to: Problem in character to Float Bin conversion
Reply with quote

by definition floating point values ( as a general case ) will never be exact values
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7936
Location: Bellevue, IA

PostPosted: Wed Mar 31, 2010 5:26 pm    Post subject:
Reply with quote

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.
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10211
Location: italy

PostPosted: Wed Mar 31, 2010 5:30 pm    Post subject: Reply to: Problem in character to Float Bin conversion
Reply with quote

and to add to Robert considerations
there are base10 numbers which cannot be represented as base2 numbers
( fractional numbers of course )
Back to top
View user's profile Send private message
nidhi.palsule

New User


Joined: 17 Feb 2009
Posts: 9
Location: Pune

PostPosted: Wed Mar 31, 2010 5:45 pm    Post subject:
Reply with quote

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.
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


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

PostPosted: Wed Mar 31, 2010 8:52 pm    Post subject:
Reply with quote

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.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> PL/I & Assembler All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts SYMNAMES problem jacobdng DFSORT/ICETOOL 7 Thu Dec 22, 2016 7:47 am
No new posts File Aid to File Manager conversion murali3955 IBM Tools 4 Thu Nov 24, 2016 3:41 pm
No new posts Problem in writing Output file vickey_dw COBOL Programming 5 Mon Nov 14, 2016 11:14 pm
No new posts Conversion of a VB file to FB. isssal DFSORT/ICETOOL 1 Mon Oct 31, 2016 10:23 pm
No new posts Problem in Running Query via JCL vickey_dw DB2 3 Tue Oct 18, 2016 11:11 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us