Lahey Support
08-15-2003, 01:19 AM
Dear All:
I want to get a integer of the last 6 digits of a real*8 number,
that is, input -.1234567890123456D308
and I want to get an integer 123456.
I wrote a code as following, but could NOT get what I want...
Where did I go wrong?
Thanks
Cosine
Jan/23/1999 UT
...
REAL(8), INTENT(IN) :: x ! <-- here x is input as
! -.1234567890123456D308
^^^^^^
! The numbers I want
REAL(8) :: xx, dtmp
INTEGER :: w, itmp
xx = ABS(x)
w = -FLOOR( LOG10(xx)+1. )
dtmp = 10.D0**w*xx
WRITE(*,*) ' dtmp = ', dtmp ! Replied me
! 0.123456789012346
itmp = FLOOR( 10.D0**16*( dtmp-REAL(itmp,8)/10.D0**9 ) )
WRITE(*,*) ' itmp = ', itmp ! Replied me
! 123455
! I want 123456
__________________________________________________ ____
Get Your Private, Free Email at http://www.hotmail.com
I want to get a integer of the last 6 digits of a real*8 number,
that is, input -.1234567890123456D308
and I want to get an integer 123456.
I wrote a code as following, but could NOT get what I want...
Where did I go wrong?
Thanks
Cosine
Jan/23/1999 UT
...
REAL(8), INTENT(IN) :: x ! <-- here x is input as
! -.1234567890123456D308
^^^^^^
! The numbers I want
REAL(8) :: xx, dtmp
INTEGER :: w, itmp
xx = ABS(x)
w = -FLOOR( LOG10(xx)+1. )
dtmp = 10.D0**w*xx
WRITE(*,*) ' dtmp = ', dtmp ! Replied me
! 0.123456789012346
itmp = FLOOR( 10.D0**16*( dtmp-REAL(itmp,8)/10.D0**9 ) )
WRITE(*,*) ' itmp = ', itmp ! Replied me
! 123455
! I want 123456
__________________________________________________ ____
Get Your Private, Free Email at http://www.hotmail.com