Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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: 10327
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: 8165
Location: East Dubuque, Illinois, USA

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: 10327
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: 1777
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 LMINIT problem - not finding DDNAME Danielle.Filteau CLIST & REXX 7 Tue Sep 19, 2017 9:57 pm
No new posts Problem commiting to DB2 from IMS MPP Ole Soerensen IMS DB/DC 2 Wed Jul 26, 2017 5:19 pm
No new posts Extra character appears in file when ... Balu5491 All Other Mainframe Topics 1 Wed Jul 26, 2017 2:39 pm
No new posts Strings with double quotes having pro... raja Arumugam All Other Mainframe Topics 11 Thu Mar 30, 2017 10:34 am
No new posts Problem reading GTF trace output danik56 ABENDS & Debugging 7 Thu Mar 16, 2017 1:02 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us