IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Problem in character to Float Bin conversion


IBM Mainframe Forums -> PL/I & Assembler
Post new topic   Reply to topic
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
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

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Wed Mar 31, 2010 5:25 pm
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Mar 31, 2010 5:26 pm
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

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Wed Mar 31, 2010 5:30 pm
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
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: 1788
Location: Bloomington, IL

PostPosted: Wed Mar 31, 2010 8:52 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> PL/I & Assembler

 


Similar Topics
Topic Forum Replies
No new posts Map Vols and Problem Dataset All Other Mainframe Topics 2
No new posts 10 byte RBA conversion DB2 2
No new posts 10 byte RBA conversion -non applicati... JCL & VSAM 1
No new posts file manager is doing string conversion IBM Tools 3
No new posts Panvalet - 9 Character name - Issue c... CA Products 6
Search our Forums:

Back to Top