Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28499 Discussions

Round decimal digits of a double float number

ilexsp
Beginner
358 Views

Hello

Im a doubt: I need use double float numbers but I wish that these numbers have a fixed accuracy of only 3 or 4digits. For example:

REAL*8TOUT, BUF(5000,17)

TOUT = (BUF(i,17) - BUF(i-1,17))*60.0D0

resulting in (for example):

TOUT= 10.2839999999995

But I need that this number is rounded to 10.2840000000000.

Does anybody know how I can resolve this problem?

Thanks

IlexSP

0 Kudos
1 Reply
TimP
Honored Contributor III
358 Views
From what you posted, I don't know whether you have unrealistic expectations, or have overlooked the Fortran FORMAT specifications, or ..... ?
When you take the difference of two nearly equal binary values, with bits just sufficient to represent 15 or more decimal digits, the results you got are to be expected.
0 Kudos
Reply