Ask Your Question
0

Read float value from file c++

asked 2013-02-16 11:19:56 -0600

BMR gravatar image

i have a text file of values

133.25 129.40 41.69 2.915

when i read it:

fscanf(File,"%f",&floatNumber[i]);

i get thes values

1.3325000000000000e+002, 1.2939999389648437e+002, 4.1689998626708984e+001 2.9149999618530273e+000

the first value is ok but the other three values why they are different ??

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-02-16 11:36:40 -0600

The reason of difference is floating point precision. Not all decimal floating point values can be represented in machine arithmetic precisely.

edit flag offensive delete link more

Comments

berak gravatar imageberak ( 2013-02-17 01:39:53 -0600 )edit

Question Tools

Stats

Asked: 2013-02-16 11:19:56 -0600

Seen: 861 times

Last updated: Feb 16 '13